恐怕我信息超载了。我的 iPad 应用程序 (iOS 5.1) 有一个教程页面。我正在尝试以这样一种方式创建教程页面,即用户可以在图像(显示教程信息)上向左或向右滑动以移动到教程的上一部分或下一部分。
_scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 704)];
_scrollview.backgroundColor = [UIColor grayColor];
_scrollview.contentSize = CGSizeMake(700, 700);
_scrollview.minimumZoomScale = 1.0;
_scrollview.maximumZoomScale = 1.0;
_scrollview.pagingEnabled = YES;
_imgViews = [NSMutableArray arrayWithCapacity:NUMPICS];
for (int i = 0; i < NUMPICS; i++) {
NSString *imgPath = [NSString stringWithFormat:@"%@/%d.png", [[NSBundle mainBundle] resourcePath], i+1];
UIImage *image = [UIImage imageWithContentsOfFile:imgPath];
UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
imgView.frame = CGRectOffset(imgView.frame, 10, 10);
[_imgViews addObject:imgView];
[_scrollview addSubview:imgView];
}
[_scrollview bringSubviewToFront:[_imgViews objectAtIndex:0]];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeNext:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[_scrollview addGestureRecognizer:swipeLeft];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipePrev:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[_scrollview addGestureRecognizer:swipeRight];
[self.view addSubview:_scrollview];
_pageview = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 654, 768, 50)];
_pageview.numberOfPages = [_imgViews count];
_pageview.currentPage = 0;
_pageview.backgroundColor = [UIColor grayColor];
_pageview.userInteractionEnabled = NO;
[self.view addSubview:_pageview];
但这显然不是我想要的。我现在可以滑动页面来移动图像,但我想滑动图像(这将占据整个屏幕并让它扫到下一张图像。请注意,这必须以编程方式完成,而不是通过情节提要IB的。
实现这一目标的最佳方法是什么?
谢谢