keep delete
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
//
|
||||
// EmptyDataView.h
|
||||
// YuMi
|
||||
//
|
||||
// Created by P on 2024/12/23.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface EmptyDataView : UIView
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@@ -1,20 +0,0 @@
|
||||
//
|
||||
// EmptyDataView.m
|
||||
// YuMi
|
||||
//
|
||||
// Created by P on 2024/12/23.
|
||||
//
|
||||
|
||||
#import "EmptyDataView.h"
|
||||
|
||||
@implementation EmptyDataView
|
||||
|
||||
/*
|
||||
// Only override drawRect: if you perform custom drawing.
|
||||
// An empty implementation adversely affects performance during animation.
|
||||
- (void)drawRect:(CGRect)rect {
|
||||
// Drawing code
|
||||
}
|
||||
*/
|
||||
|
||||
@end
|
@@ -1,34 +0,0 @@
|
||||
//
|
||||
// MoliMoneyLabel.h
|
||||
// YuMi
|
||||
//
|
||||
// Created by P on 2025/2/25.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface MoliMoneyLabel : UIView
|
||||
|
||||
/// 带金币 icon 的 label view
|
||||
/// - Parameters:
|
||||
/// - textColor: 文本颜色
|
||||
/// - font: 文本字体
|
||||
/// - position: icon 位置,1: 左,2:右
|
||||
/// - size: icon 大小
|
||||
+ (MoliMoneyLabel *)moneyLabelWithTextColot:(UIColor *)textColor font:(UIFont *)font moneyPostion:(NSInteger)position moneySize:(CGSize)size;
|
||||
|
||||
- (void)updateContent:(NSString *)content;
|
||||
- (void)updateFont:(UIFont *)font size:(CGSize)size;
|
||||
- (void)displayIcon:(BOOL)displayOrNot;
|
||||
- (void)updateSpacing:(NSInteger)space;
|
||||
- (void)updateLabelAlignment:(NSTextAlignment)alignment;
|
||||
- (void)insertSpaceAtLeast;
|
||||
|
||||
- (void)hideAll;
|
||||
- (void)removeSpace;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@@ -1,90 +0,0 @@
|
||||
//
|
||||
// MoliMoneyLabel.m
|
||||
// YuMi
|
||||
//
|
||||
// Created by P on 2025/2/25.
|
||||
//
|
||||
|
||||
#import "MoliMoneyLabel.h"
|
||||
|
||||
@interface MoliMoneyLabel()
|
||||
|
||||
@property(nonatomic, strong) UILabel *label;
|
||||
@property(nonatomic, strong) UIImageView *money;
|
||||
@property(nonatomic, strong) UIView *spaceView;
|
||||
@property(nonatomic, strong) UIStackView *stackView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MoliMoneyLabel
|
||||
|
||||
+ (MoliMoneyLabel *)moneyLabelWithTextColot:(UIColor *)textColor
|
||||
font:(UIFont *)font
|
||||
moneyPostion:(NSInteger)position
|
||||
moneySize:(CGSize)size {
|
||||
MoliMoneyLabel *containerView = [[MoliMoneyLabel alloc] init];
|
||||
containerView.label = [UILabel labelInitWithText:@"" font:font textColor:textColor];
|
||||
containerView.label.minimumScaleFactor = 0.7;
|
||||
containerView.label.adjustsFontSizeToFitWidth = YES;
|
||||
|
||||
containerView.money = [[UIImageView alloc] initWithImage:kImage(@"moli_money_icon")];
|
||||
containerView.money.contentMode = UIViewContentModeScaleAspectFill;
|
||||
|
||||
containerView.spaceView = [[UIView alloc] init];
|
||||
|
||||
NSArray *subviews = position == 1 ? @[containerView.spaceView, containerView.money, containerView.label] : @[containerView.spaceView, containerView.label, containerView.money];
|
||||
containerView.stackView = [[UIStackView alloc] initWithArrangedSubviews:subviews];
|
||||
containerView.stackView.spacing = 3;
|
||||
containerView.stackView.distribution = UIStackViewDistributionFillProportionally;
|
||||
containerView.stackView.alignment = UIStackViewAlignmentCenter;
|
||||
[containerView addSubview:containerView.stackView];
|
||||
[containerView.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.mas_equalTo(containerView);
|
||||
}];
|
||||
|
||||
[containerView.money mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.size.mas_equalTo(size);
|
||||
}];
|
||||
|
||||
return containerView;
|
||||
}
|
||||
|
||||
- (void)hideAll {
|
||||
self.spaceView.hidden = YES;
|
||||
self.stackView.hidden = YES;
|
||||
self.money.hidden = YES;
|
||||
}
|
||||
|
||||
- (void)removeSpace {
|
||||
[self.stackView removeArrangedSubview:self.spaceView];
|
||||
}
|
||||
|
||||
- (void)updateSpacing:(NSInteger)space {
|
||||
self.stackView.spacing = space;
|
||||
}
|
||||
|
||||
- (void)displayIcon:(BOOL)displayOrNot {
|
||||
self.money.hidden = !displayOrNot;
|
||||
}
|
||||
|
||||
- (void)updateContent:(NSString *)content {
|
||||
self.label.text = content;
|
||||
}
|
||||
|
||||
- (void)updateFont:(UIFont *)font size:(CGSize)size {
|
||||
self.label.font = font;
|
||||
[self.money mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.size.mas_equalTo(size);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)updateLabelAlignment:(NSTextAlignment)alignment {
|
||||
self.label.textAlignment = alignment;
|
||||
}
|
||||
|
||||
- (void)insertSpaceAtLeast {
|
||||
UIView *space = [[UIView alloc] init];
|
||||
[self.stackView addArrangedSubview:space];
|
||||
}
|
||||
|
||||
@end
|
@@ -1,18 +0,0 @@
|
||||
//
|
||||
// SexAgeLabel.h
|
||||
// YuMi
|
||||
//
|
||||
// Created by P on 2024/12/11.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SexAgeLabel : UIView
|
||||
|
||||
- (void)updateSex:(BOOL)isMale age:(NSInteger)age;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@@ -1,65 +0,0 @@
|
||||
//
|
||||
// SexAgeLabel.m
|
||||
// YuMi
|
||||
//
|
||||
// Created by P on 2024/12/11.
|
||||
//
|
||||
|
||||
#import "SexAgeLabel.h"
|
||||
|
||||
@interface SexAgeLabel ()
|
||||
|
||||
@property(nonatomic, strong) UIView *pillBackground;
|
||||
@property(nonatomic, strong) UIImageView *sexImageView;
|
||||
@property(nonatomic, strong) UILabel *ageLabel;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SexAgeLabel
|
||||
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
|
||||
// self.frame = CGRectMake(0, 0, 35, 16);
|
||||
|
||||
[self setCornerRadius:8];
|
||||
[self addGradientBackgroundWithColors:@[[UIColor redColor], [UIColor blueColor]] startPoint:CGPointMake(0.5, 0) endPoint:CGPointMake(0.5, 1) cornerRadius:8];
|
||||
|
||||
[self addSubview:self.sexImageView];
|
||||
[self addSubview:self.ageLabel];
|
||||
[self.sexImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerY.mas_equalTo(self);
|
||||
make.leading.mas_equalTo(2);
|
||||
make.width.height.mas_equalTo(8);
|
||||
}];
|
||||
|
||||
[self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerY.mas_equalTo(self);
|
||||
make.leading.mas_equalTo(self.sexImageView.mas_trailing).offset(2);
|
||||
make.trailing.mas_equalTo(-2);
|
||||
}];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)updateSex:(BOOL)isMale age:(NSInteger)age {
|
||||
self.sexImageView.image = isMale ? kImage(@"session_user_sex_male") : kImage(@"session_user_sex_female");
|
||||
self.ageLabel.text = @(age).stringValue;
|
||||
}
|
||||
|
||||
- (UIImageView *)sexImageView {
|
||||
if (!_sexImageView) {
|
||||
_sexImageView = [[UIImageView alloc] init];
|
||||
_sexImageView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
}
|
||||
return _sexImageView;
|
||||
}
|
||||
|
||||
- (UILabel *)ageLabel {
|
||||
if (!_ageLabel) {
|
||||
_ageLabel = [UILabel labelInitWithText:@"" font:kFontSemibold(12) textColor:[UIColor whiteColor]];
|
||||
}
|
||||
return _ageLabel;
|
||||
}
|
||||
|
||||
@end
|
@@ -1,38 +0,0 @@
|
||||
//
|
||||
// YMSwitch.h
|
||||
// YUMI
|
||||
//
|
||||
// Created by YUMI on 2023/2/9.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef enum {
|
||||
CHSwitchShapeOval,
|
||||
CHSwitchShapeRectangle,
|
||||
CHSwitchShapeRectangleNoCorner
|
||||
} CHSwitchShape;
|
||||
|
||||
@interface XPSwitch : UIControl<UIGestureRecognizerDelegate>
|
||||
/** 开关状态读取与设置 */
|
||||
@property (nonatomic, getter = isOn) BOOL on;
|
||||
/** 开关形状枚举值:默认CHSwitchShapeOval */
|
||||
@property (nonatomic, assign) CHSwitchShape shape;
|
||||
/** 打开时的颜色 */
|
||||
@property (nonatomic, strong) UIColor *onTintColor;
|
||||
/** 关闭时的颜色 */
|
||||
@property (nonatomic, strong) UIColor *tintColor;
|
||||
/** 圆点颜色 */
|
||||
@property (nonatomic, strong) UIColor *thumbTintColor;
|
||||
/** 是否需要阴影效果 */
|
||||
@property (nonatomic, assign) BOOL shadow;
|
||||
/** 关闭时的阴影颜色 */
|
||||
@property (nonatomic, strong) UIColor *tintBorderColor;
|
||||
/** 打开时的阴影颜色 */
|
||||
@property (nonatomic, strong) UIColor *onTintBorderColor;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@@ -1,372 +0,0 @@
|
||||
//
|
||||
// YMSwitch.m
|
||||
// YUMI
|
||||
//
|
||||
// Created by YUMI on 2023/2/9.
|
||||
//
|
||||
|
||||
#import "XPSwitch.h"
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
static const CGFloat kAnimateDuration = 0.3f;
|
||||
static const CGFloat kHorizontalAdjustment = 3.0f;
|
||||
static const CGFloat kRectShapeCornerRadius = 4.0f;
|
||||
static const CGFloat kThumbShadowOpacity = 0.3f;
|
||||
static const CGFloat kThumbShadowRadius = 0.5f;
|
||||
static const CGFloat kSwitchBorderWidth = 1.75f;
|
||||
|
||||
@interface XPSwitch ()
|
||||
|
||||
@property (nonatomic, strong) UIView *onBackgroundView;
|
||||
@property (nonatomic, strong) UIView *offBackgroundView;
|
||||
@property (nonatomic, strong) UIView *thumbView;
|
||||
|
||||
@end
|
||||
@implementation XPSwitch
|
||||
|
||||
@synthesize onBackgroundView = _onBackgroundView;
|
||||
@synthesize offBackgroundView = _offBackgroundView;
|
||||
@synthesize thumbView = _thumbView;
|
||||
@synthesize on = _on;
|
||||
@synthesize shape = _shape;
|
||||
@synthesize onTintColor = _onTintColor;
|
||||
@synthesize tintColor = _tintColor;
|
||||
@synthesize thumbTintColor = _thumbTintColor;
|
||||
@synthesize shadow = _shadow;
|
||||
@synthesize onTintBorderColor = _onTintBorderColor;
|
||||
@synthesize tintBorderColor = _tintBorderColor;
|
||||
|
||||
#pragma mark - View
|
||||
- (id)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self setupUI];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) awakeFromNib {
|
||||
[super awakeFromNib];
|
||||
|
||||
[self setupUI];
|
||||
}
|
||||
|
||||
- (void)setupUI {
|
||||
self.shape = CHSwitchShapeOval;
|
||||
|
||||
[self setBackgroundColor:[UIColor clearColor]];
|
||||
|
||||
// Background view for ON
|
||||
self.onBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
|
||||
[self.onBackgroundView setBackgroundColor:[UIColor colorWithRed:(19.0f/255.0f) green:(121.0f/255.0f) blue:(208.0f/255.0f) alpha:1.0f]];
|
||||
[self.onBackgroundView.layer setCornerRadius:self.frame.size.height/2];
|
||||
[self.onBackgroundView.layer setShouldRasterize:YES];
|
||||
[self.onBackgroundView.layer setRasterizationScale:[UIScreen mainScreen].scale];
|
||||
[self addSubview:self.onBackgroundView];
|
||||
|
||||
// Background view for OFF
|
||||
self.offBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
|
||||
[self.offBackgroundView setBackgroundColor:[UIColor whiteColor]];
|
||||
[self.offBackgroundView.layer setCornerRadius:self.frame.size.height/2];
|
||||
[self.offBackgroundView.layer setShouldRasterize:YES];
|
||||
[self.offBackgroundView.layer setRasterizationScale:[UIScreen mainScreen].scale];
|
||||
[self addSubview:self.offBackgroundView];
|
||||
|
||||
// Round switch view
|
||||
self.thumbView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.height-kHorizontalAdjustment, self.frame.size.height-kHorizontalAdjustment)];
|
||||
[self.thumbView setBackgroundColor:[UIColor whiteColor]];
|
||||
[self.thumbView setUserInteractionEnabled:YES];
|
||||
[self.thumbView.layer setCornerRadius:(self.frame.size.height-kHorizontalAdjustment)/2];
|
||||
[self.thumbView.layer setShadowOffset:CGSizeMake(0, 1)];
|
||||
[self.thumbView.layer setShouldRasterize:YES];
|
||||
[self.thumbView.layer setShadowOpacity:kThumbShadowOpacity];
|
||||
[self.thumbView.layer setRasterizationScale:[UIScreen mainScreen].scale];
|
||||
[self addSubview:self.thumbView];
|
||||
self.shadow = YES;
|
||||
|
||||
// Default to OFF position
|
||||
[self.thumbView setCenter:CGPointMake(self.thumbView.frame.size.width/2, self.frame.size.height/2)];
|
||||
|
||||
// Handle Thumb Tap Gesture
|
||||
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
|
||||
action:@selector(handleSwitchTap:)];
|
||||
[tapGestureRecognizer setDelegate:self];
|
||||
[self.thumbView addGestureRecognizer:tapGestureRecognizer];
|
||||
|
||||
// Handle Background Tap Gesture
|
||||
UITapGestureRecognizer *tapBgGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleBgTap:)];
|
||||
[tapBgGestureRecognizer setDelegate:self];
|
||||
[self addGestureRecognizer:tapBgGestureRecognizer];
|
||||
|
||||
// Handle Thumb Pan Gesture
|
||||
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
|
||||
[panGestureRecognizer setDelegate:self];
|
||||
[self.thumbView addGestureRecognizer:panGestureRecognizer];
|
||||
|
||||
[self setOn:NO];
|
||||
}
|
||||
|
||||
#pragma mark - Accessor
|
||||
- (BOOL)isOn {
|
||||
return _on;
|
||||
}
|
||||
|
||||
- (void)setOn:(BOOL)on {
|
||||
if (_on != on)
|
||||
_on = on;
|
||||
|
||||
if (_on) {
|
||||
[self.onBackgroundView setAlpha:1.0];
|
||||
self.offBackgroundView.transform = CGAffineTransformMakeScale(0.0, 0.0);
|
||||
|
||||
self.thumbView.center = CGPointMake(self.onBackgroundView.frame.size.width - (self.thumbView.frame.size.width + kHorizontalAdjustment)/2, self.thumbView.center.y);
|
||||
}
|
||||
else {
|
||||
[self.onBackgroundView setAlpha:0.0];
|
||||
self.offBackgroundView.transform = CGAffineTransformMakeScale(1.0, 1.0);
|
||||
|
||||
self.thumbView.center = CGPointMake((self.thumbView.frame.size.width+kHorizontalAdjustment)/2, self.thumbView.center.y);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setOnTintColor:(UIColor *)color
|
||||
{
|
||||
if (_onTintColor != color)
|
||||
_onTintColor = color;
|
||||
|
||||
[self.onBackgroundView setBackgroundColor:color];
|
||||
}
|
||||
|
||||
- (void)setOnTintBorderColor:(UIColor *)color
|
||||
{
|
||||
if (_onTintBorderColor != color)
|
||||
_onTintBorderColor = color;
|
||||
|
||||
[self.onBackgroundView.layer setBorderColor:color.CGColor];
|
||||
|
||||
if (color)
|
||||
[self.onBackgroundView.layer setBorderWidth:kSwitchBorderWidth];
|
||||
else
|
||||
[self.onBackgroundView.layer setBorderWidth:0.0];
|
||||
}
|
||||
|
||||
- (void)setTintColor:(UIColor *)color
|
||||
{
|
||||
if (_tintColor != color)
|
||||
_tintColor = color;
|
||||
|
||||
[self.offBackgroundView setBackgroundColor:color];
|
||||
}
|
||||
|
||||
- (void)setTintBorderColor:(UIColor *)color
|
||||
{
|
||||
if (_tintBorderColor != color)
|
||||
_tintBorderColor = color;
|
||||
|
||||
[self.offBackgroundView.layer setBorderColor:color.CGColor];
|
||||
|
||||
if (color)
|
||||
[self.offBackgroundView.layer setBorderWidth:kSwitchBorderWidth];
|
||||
else
|
||||
[self.offBackgroundView.layer setBorderWidth:0.0];
|
||||
}
|
||||
|
||||
- (void)setThumbTintColor:(UIColor *)color
|
||||
{
|
||||
if (_thumbTintColor != color)
|
||||
_thumbTintColor = color;
|
||||
|
||||
[self.thumbView setBackgroundColor:color];
|
||||
}
|
||||
|
||||
- (void)setShape:(CHSwitchShape)newShape
|
||||
{
|
||||
if (_shape != newShape)
|
||||
_shape = newShape;
|
||||
|
||||
if (newShape == CHSwitchShapeOval)
|
||||
{
|
||||
[self.onBackgroundView.layer setCornerRadius:self.frame.size.height/2];
|
||||
[self.offBackgroundView.layer setCornerRadius:self.frame.size.height/2];
|
||||
[self.thumbView.layer setCornerRadius:(self.frame.size.height-kHorizontalAdjustment)/2];
|
||||
}
|
||||
else if (newShape == CHSwitchShapeRectangle)
|
||||
{
|
||||
[self.onBackgroundView.layer setCornerRadius:kRectShapeCornerRadius];
|
||||
[self.offBackgroundView.layer setCornerRadius:kRectShapeCornerRadius];
|
||||
[self.thumbView.layer setCornerRadius:kRectShapeCornerRadius];
|
||||
}
|
||||
else if (newShape == CHSwitchShapeRectangleNoCorner)
|
||||
{
|
||||
[self.onBackgroundView.layer setCornerRadius:0];
|
||||
[self.offBackgroundView.layer setCornerRadius:0];
|
||||
[self.thumbView.layer setCornerRadius:0];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setShadow:(BOOL)showShadow
|
||||
{
|
||||
if (_shadow != showShadow)
|
||||
_shadow = showShadow;
|
||||
|
||||
if (showShadow)
|
||||
{
|
||||
[self.thumbView.layer setShadowOffset:CGSizeMake(0, 1)];
|
||||
[self.thumbView.layer setShadowRadius:kThumbShadowRadius];
|
||||
[self.thumbView.layer setShadowOpacity:kThumbShadowOpacity];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self.thumbView.layer setShadowRadius:0.0];
|
||||
[self.thumbView.layer setShadowOpacity:0.0];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Animation
|
||||
- (void)animateToDestination:(CGPoint)centerPoint withDuration:(CGFloat)duration switch:(BOOL)on
|
||||
{
|
||||
[UIView animateWithDuration:duration
|
||||
delay:0.0f
|
||||
options:UIViewAnimationOptionCurveEaseOut
|
||||
animations:^{
|
||||
self.thumbView.center = centerPoint;
|
||||
|
||||
if (on)
|
||||
{
|
||||
[self.onBackgroundView setAlpha:1.0];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self.onBackgroundView setAlpha:0.0];
|
||||
}
|
||||
|
||||
}
|
||||
completion:^(BOOL finished) {
|
||||
if (finished)
|
||||
{
|
||||
[self updateSwitch:on];
|
||||
}
|
||||
|
||||
}];
|
||||
|
||||
[UIView animateWithDuration:duration
|
||||
delay:0.075f
|
||||
options:UIViewAnimationOptionCurveEaseOut
|
||||
animations:^{
|
||||
if (on)
|
||||
{
|
||||
self.offBackgroundView.transform = CGAffineTransformMakeScale(0.0, 0.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.offBackgroundView.transform = CGAffineTransformMakeScale(1.0, 1.0);
|
||||
}
|
||||
|
||||
}
|
||||
completion:^(BOOL finished) {
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
|
||||
#pragma mark - Gesture Recognizers
|
||||
- (void)handlePan:(UIPanGestureRecognizer *)recognizer
|
||||
{
|
||||
CGPoint translation = [recognizer translationInView:self.thumbView];
|
||||
|
||||
// Check the new center to see if within the boud
|
||||
CGPoint newCenter = CGPointMake(recognizer.view.center.x + translation.x,
|
||||
recognizer.view.center.y);
|
||||
if (newCenter.x < (recognizer.view.frame.size.width+kHorizontalAdjustment)/2 || newCenter.x > self.onBackgroundView.frame.size.width-(recognizer.view.frame.size.width+kHorizontalAdjustment)/2)
|
||||
{
|
||||
// New center is Out of bound. Animate to left or right position
|
||||
if(recognizer.state == UIGestureRecognizerStateBegan ||
|
||||
recognizer.state == UIGestureRecognizerStateChanged)
|
||||
{
|
||||
CGPoint velocity = [recognizer velocityInView:self.thumbView];
|
||||
|
||||
if (velocity.x >= 0)
|
||||
{
|
||||
// Animate move to right
|
||||
[self animateToDestination:CGPointMake(self.onBackgroundView.frame.size.width - (self.thumbView.frame.size.width+kHorizontalAdjustment)/2, recognizer.view.center.y) withDuration:kAnimateDuration switch:YES];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Animate move to left
|
||||
[self animateToDestination:CGPointMake((self.thumbView.frame.size.width+kHorizontalAdjustment)/2, recognizer.view.center.y) withDuration:kAnimateDuration switch:NO];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Only allow vertical pan
|
||||
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
|
||||
recognizer.view.center.y);
|
||||
[recognizer setTranslation:CGPointMake(0, 0) inView:self.thumbView];
|
||||
|
||||
CGPoint velocity = [recognizer velocityInView:self.thumbView];
|
||||
|
||||
if(recognizer.state == UIGestureRecognizerStateEnded)
|
||||
{
|
||||
if (velocity.x >= 0)
|
||||
{
|
||||
if (recognizer.view.center.x < self.onBackgroundView.frame.size.width - (self.thumbView.frame.size.width+kHorizontalAdjustment)/2)
|
||||
{
|
||||
// Animate move to right
|
||||
[self animateToDestination:CGPointMake(self.onBackgroundView.frame.size.width - (self.thumbView.frame.size.width+kHorizontalAdjustment)/2, recognizer.view.center.y) withDuration:kAnimateDuration switch:YES];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Animate move to left
|
||||
[self animateToDestination:CGPointMake((self.thumbView.frame.size.width+kHorizontalAdjustment)/2, recognizer.view.center.y) withDuration:kAnimateDuration switch:NO];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleSwitchTap:(UIPanGestureRecognizer *)recognizer
|
||||
{
|
||||
if (recognizer.state == UIGestureRecognizerStateEnded)
|
||||
{
|
||||
if (self.isOn)
|
||||
{
|
||||
// Animate move to left
|
||||
[self animateToDestination:CGPointMake((self.thumbView.frame.size.width+kHorizontalAdjustment)/2, recognizer.view.center.y) withDuration:kAnimateDuration switch:NO];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Animate move to right
|
||||
[self animateToDestination:CGPointMake(self.onBackgroundView.frame.size.width - (self.thumbView.frame.size.width+kHorizontalAdjustment)/2, recognizer.view.center.y) withDuration:kAnimateDuration switch:YES];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleBgTap:(UIPanGestureRecognizer *)recognizer
|
||||
{
|
||||
if (recognizer.state == UIGestureRecognizerStateEnded)
|
||||
{
|
||||
if (self.isOn)
|
||||
{
|
||||
// Animate move to left
|
||||
[self animateToDestination:CGPointMake((self.thumbView.frame.size.width+kHorizontalAdjustment)/2, self.thumbView.center.y) withDuration:kAnimateDuration switch:NO];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Animate move to right
|
||||
[self animateToDestination:CGPointMake(self.onBackgroundView.frame.size.width - (self.thumbView.frame.size.width+kHorizontalAdjustment)/2, self.thumbView.center.y) withDuration:kAnimateDuration switch:YES];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
- (void)updateSwitch:(BOOL)on
|
||||
{
|
||||
if (_on != on)
|
||||
_on = on;
|
||||
|
||||
[self sendActionsForControlEvents:UIControlEventValueChanged];
|
||||
}
|
||||
|
||||
@end
|
Reference in New Issue
Block a user