实现滑块从不同阶段回到起始位的可触发方法。(干货)

#import "ViewController.h"

@interface ViewController ()

{

UIImageView *imageView;

UISlider * _slider;

BOOL isZero;

BOOL isTwo;

}

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 100, 300, 50)];

imageView.image = [UIImage imageNamed:@"chat.png"];

[self.view addSubview:imageView];

_slider = [[UISlider alloc]initWithFrame:CGRectMake(10, 100, 300, 50)];

_slider.minimumValue = 0;

_slider.maximumValue = 2;

_slider.continuous = NO;

[self.view addSubview:_slider];

[_slider addTarget:self action:@selector(log:) forControlEvents:UIControlEventValueChanged];

// 设置滑块图案

[_slider setThumbImage:[UIImage imageNamed:@"smile.png"]forState:UIControlStateNormal];

// 滑块的滑动左右颜色

_slider.minimumTrackTintColor = [UIColor clearColor];

_slider.maximumTrackTintColor = [UIColor clearColor];

isZero = 1;//判断触发带单

isTwo = 0;//判断取消带单

}

-(void)log:(UISlider *)slider

{

NSLog(@"%f",_slider.value);

if (_slider.value>=1) {

NSLog(@"123");

[_slider setValue:2 animated:YES];

if (isZero==1) {

isTwo = 1;

NSLog(@"触发带单");

isZero= 0;

}else

{

NSLog(@"未触发带单");

}

}else

{

//此时 设置向右滑提示的背景图

imageView.image = [UIImage imageNamed:@"chat.png"];

NSLog(@"afasf");

[_slider setValue:0 animated:YES];

if (isTwo==1) {

isZero = 1;

NSLog(@"触发取消");

isTwo = 0;

}else

{

NSLog(@"未触发取消");

}

}

}

你可能感兴趣的:(实现滑块从不同阶段回到起始位的可触发方法。(干货))