How to auto scroll UIScrollView using timer?

后端 未结 5 499
粉色の甜心
粉色の甜心 2020-12-08 11:29

I have a UIScrollView to show images. I need a timer to show the images one after another, after every 5 seconds. How to initiate UIScrollView even

5条回答
  •  难免孤独
    2020-12-08 11:49

    Add the variable int h to your interface, and yourScrollView as a property. Then:

    [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
    
    - (void) onTimer {
    
        // Updates the variable h, adding 100 (put your own value here!)
        h += 100; 
    
        //This makes the scrollView scroll to the desired position  
        yourScrollView.contentOffset = CGPointMake(0, h);  
    
    }
    

提交回复
热议问题