UIScrollView *scrl = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768,1024)];
scrl.contentSize = CGSizeMake(768 * 8, 1024);这是我的UIScrollView的定义,我有一个用8幅图像填充的卷轴,每个图像是一个768*1024,如何使UIScrollView幻灯片显示,每个图像停留2秒并滑到下一个图像,我如何做到这一点?
发布于 2011-07-31 10:50:26
您可以使用UIImageView而不是UIScrollView。
在您的.h文件中:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
int imageId;
UIImageView *imageView;
}
@property(nonatomic, retain) IBOutlet UIImageView * imageView;
@end在您的.m文件中:
@implementation ViewController
#import <QuartzCore/CAAnimation.h>
#define NUMBER_OF_IMAGES 8;
@synthesize imageView;
- (void)viewDidLoad
{
[super viewDidLoad];
imageId = 0;
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(changeImage) userInfo:nil repeats:YES];
}
-(void)changeImage
{
imageId = imageId + 1;
CATransition * trs = [CATransition animation];
trs.duration = 1;
[trs setType:kCATransitionPush];
int id = imageId % NUMBER_OF_IMAGES;
imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image_%d.jpg", id]];
[imageView.layer addAnimation:trs forKey:kCATransition];
}
@end您需要将QuartzCore.framework添加到项目中。
发布于 2012-01-02 14:49:52
我不会给你任何密码(那是你的工作).
下面是如何做这样一件事:
有一个处理分页的父UIScrollView -必须实现scrollViewDidScroll的委托方法:
拥有一个UIPageControl (用于跟踪您在哪个页面上,代码明智或UI明智)
对缩放很重要: 1.创建UIScrollView的子类,并将UIImageView作为子视图添加到其中。2.允许滚动,不分页。3.使这个子类实现viewForZoomingInScrollView的委托方法:(返回UIImageView)
https://stackoverflow.com/questions/6888378
复制相似问题