简体   繁体   English

滑块与NSTimer iPhone

[英]Slider with NSTimer iPhone

I want to display an image for 5-6 secs and then link a slider to it to show increasing time. 我希望显示图像5-6秒,然后将滑块链接到它以显示增加的时间。 That is say if time is 0 seconds, slider is at extreme left and if Timer is 1 seconds slider moves appropriately towards right and if Timer is 3 seconds than slider is in the middle and as time increases gradually 4 -5 seconds it moves right and at 6 seconds its on its extreme right. 也就是说,如果时间为0秒,则滑块位于极左侧,如果计时器为1秒,则滑块向右移动,如果计时器比滑块位于3秒,则滑块位于中间,随着时间逐渐增加4 -5秒,滑块向右移动在最右边的6秒钟。 Can you guide me on this 你能指导我吗?

Use below one 使用下面一个

 timerForSlider = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateSlider) userInfo:nil repeats:YES];//timerForSlider in .h file

-(void)updateSlider
{
    [slider setValue:slider.value+1];
    if(slider.value==6)
    {
        [timerForSlider invalidate];
    }
}

In XIB set slider minimumVal =0; 在XIB中设置滑块minimumVal = 0; MaximumVal=6; MaximumVal = 6; initialVal = 0; initialVal = 0;

this is timer callback (selector): 这是计时器回调(选择器):

-(void) timer {
    //dSliderValue - step of slider moveing. set it to 2
    if (slider.value+dSliderValue <= 60) [slider setValue:slider.value+dSliderValue];
    else {
        [t invalidate];
        //any other code here, on timer stopping
    }
}

this is timer (NSTimer *t). 这是计时器(NSTimer * t)。 call it on start image showing: 在开始图像上显示:

[slider setMaximumValue:60];
[slider setValue:0];
dSliderValue = 2;
t = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(timer) userInfo:nil repeats:YES];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM