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

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

全部回复(1)
小葫芦

先不说问题,你这问题这么久没人回答的原因只有一个,看着太累了,麻烦规范下代码啊。。。下面解决问题。你的界面使用IB拖得约束吧,单纯的更改frame 是不行的,你要更新约束才行

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!