ios - 当slider位置移动之后,拖动slider的手柄,slider会回到初始的位置?
ringa_lee
ringa_lee 2017-04-17 17:31:10
0
1
270

iOS,使用ib在界面上做了一个label和一个slider,然后代码写了一个button,slider的值显示在label上,button让slider向下移动。当slider移动之后,拖动slider的手柄,slider会回到初始的位置?why?

#import "ViewController.h"

@interface ViewController ()
//@property (nonatomic, retain) UISlider *slider;
@property (nonatomic, retain) UIButton *button;

@property (weak, nonatomic) IBOutlet UILabel *label; 
@property (weak, nonatomic) IBOutlet UISlider *slider;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //设置一个button来移动slider
    _button = [[UIButton alloc] initWithFrame:CGRectMake(20, 500, 40, 40)];
    _button.backgroundColor = [UIColor blackColor];
    
    [self.view addSubview:_button];
    
    [_button addTarget:self action:@selector(checkButton) forControlEvents:UIControlEventTouchUpInside];
}

-(void)checkButton
{
    CGRect rect = _slider.frame;
    
    rect.origin.y += 20;
    
    _slider.frame = rect;
}

- (IBAction)changValue:(id)sender {
    _label.text = \[NSString stringWithFormat:@"%f",_slider.value\];
}
- (void)didReceiveMemoryWarning {
    \[super didReceiveMemoryWarning\];
    // Dispose of any resources that can be recreated.
}

@end
ringa_lee
ringa_lee

ringa_lee

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!