OGeek|极客世界-中国程序员成长平台

标题: iphone - 图像幻灯片 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 16:12
标题: iphone - 图像幻灯片

我正在开发一个简单幻灯片的应用程序。

描述:在应用程序中,我将 5 张图像存储在一个数组中。目前我将图像显示到 ScrollView 中,但我想显示存储在数组中的图像的幻灯片。我怎样才能做到这一点 ?有教程吗?

问候



Best Answer-推荐答案


我建议使用 NSTimer,这是一些基本代码。但是,必须根据您希望如何处理边缘情况来计算“页”数,例如:幻灯片放映中的最后一张图片。

看看Apple's example app PageControl ,它展示了如何在分页 ScrollView 中有效处理内存的好方法。

self.slideTimer = [NSTimer scheduledTimerWithTimeInterval:3.0
                                                   target:self 
                                                 selectorselector(slide) 
                                                 userInfo:nil 
                                                  repeats:YES];

...

- (void)slide
{
    CGRect frame = scrollView.frame;
    frame.origin.x = frame.size.width * nextImagePageNumber;
    frame.origin.y = 0;
    [scrollView scrollRectToVisible:frame animated:YES];
}

NSTimer

You use the NSTimer class to create timer objects or, more simply, timers. A timer waits until a certain time interval has elapsed and then fires, sending a specified message to a target object. For example, you could create an NSTimer object that sends a message to a window, telling it to update itself after a certain time interval.

关于iphone - 图像幻灯片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5963687/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4