ios - UIScrollView 根据时间改变位置

标签 ios objective-c uiscrollview

我正在尝试实现 UIScrollView,但我想为 ScrollView 设置动画以每 10 秒显示一次 ScrollView 的不同 View 。对于我发现的这种方法可能有所帮助:

- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;

但是你们有谁知道是否有一种方法可以根据时间实现 ScrollView 的更改?

最佳答案

你可以使用

[NSTimer scheduledTimerWithTimeInterval:10.0
target:self
selector:@selector(updateScrollPosition:)
userInfo:nil
repeats:YES];

然后在 updateScrollPosition 中,您可以相应地更新 scrollView 的偏移量。

-(void)updateScrollPosition{
    [scrollView setContentOffset:contentOffset animated:YES];
    // where contentOffset is the custom CGPoint 
    // where you want your scrollView to scroll after every 10 sec
}

关于ios - UIScrollView 根据时间改变位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33353969/

相关文章:

c++ - 将格式化数据转换为结构的简便方法

objective-c - 具有数百个数据点的 UIScrollView 最佳实践

ios - 返回数组时不兼容的 block 指针类型?

ios - 在 iOS6 中关闭和重新打开应用程序时出现 UI 问题

Objective-C 将字符串添加到 html 包中

iphone - 如何防止 iPhone 在我的应用程序充电时锁定

iphone - 如何在 ScrollView 图像中添加背景图像

ios - UIScrollView 跨设备 UI 兼容性

ios - 如何从 RGBA 创建 UIColor?

ios - 如何在 iOS 7 上使用 MFMailComposeViewController?