iOS5 滑动手势切换图像 - 请求帮助
我有很多图像想要使用手势(来回)推送。我知道 PageViewController 非常适合此操作,但我不知道如何在使用 NIB 的现有项目中使用它。
所以。我正在尝试构建 UIView 动画。我可以看到第一张图片,但手势不起作用。
我将不胜感激任何帮助。
这是两个例程之一的代码,加上手势初始化:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
NSLog(@"%s", __FUNCTION__);
return YES;
}
- (void)handleSwipe:(UISwipeGestureRecognizer *)recognizer {
NSLog(@"%s", __FUNCTION__);
switch (recognizer.direction)
{
case (UISwipeGestureRecognizerDirectionRight):
[self performSelector:@selector(previousPage:)];
//[self previousPage];
break;
case (UISwipeGestureRecognizerDirectionLeft):
[self performSelector:@selector(nextPage:)];
//[self nextPage];
break;
default:
break;
}
}
- (void)nextPage {
[UIView beginAnimations:@"fadeOut" context:nil];
[UIView setAnimationDelay:0.0f];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
pageNumber ++;
if(pageNumber > maxInfoPages)
{
pageNumber = 1;
}
NSString *imageName = [NSString stringWithFormat:@"infoPage%i.png", pageNumber];
imageView.image = [UIImage imageNamed:imageName];
NSLog(@"imageName is: %@", imageName);
NSLog(@"imageView is: %@", imageView);
imageView.clipsToBounds=YES;
self.view = imageView;
[UIView commitAnimations];
}
非常感谢
I have a number of images that I'd like to push using gestures (back and forth). I know that the PageViewController is perfect for this, but I cannot figure out how to use this in an existing project that uses NIBs.
So. I'm trying to build a UIView Animation. I can see the first image, but the gestures are not working..
I would appreciate any help..
Here is the code for one of the two routines, plus the gesture init:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
NSLog(@"%s", __FUNCTION__);
return YES;
}
- (void)handleSwipe:(UISwipeGestureRecognizer *)recognizer {
NSLog(@"%s", __FUNCTION__);
switch (recognizer.direction)
{
case (UISwipeGestureRecognizerDirectionRight):
[self performSelector:@selector(previousPage:)];
//[self previousPage];
break;
case (UISwipeGestureRecognizerDirectionLeft):
[self performSelector:@selector(nextPage:)];
//[self nextPage];
break;
default:
break;
}
}
- (void)nextPage {
[UIView beginAnimations:@"fadeOut" context:nil];
[UIView setAnimationDelay:0.0f];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
pageNumber ++;
if(pageNumber > maxInfoPages)
{
pageNumber = 1;
}
NSString *imageName = [NSString stringWithFormat:@"infoPage%i.png", pageNumber];
imageView.image = [UIImage imageNamed:imageName];
NSLog(@"imageName is: %@", imageName);
NSLog(@"imageView is: %@", imageView);
imageView.clipsToBounds=YES;
self.view = imageView;
[UIView commitAnimations];
}
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您实际上没有设置 UIGestureRecognizers 并将它们添加到您的视图中,您将不会收到任何发送到您的 viewController 的事件。因此,您需要将 UIGestureRecognizers 附加到将拦截滑动的视图。例如,在您的 viewDidLoad 方法中,您将执行以下操作:
祝您好运!
If you don't actually set up the UIGestureRecognizers and add them to your view, you will not get any events sent to your viewController. So you need to attach the UIGestureRecognizers to the view that will intercept the swipes. For example in your viewDidLoad method you would do something along the lines of:
Good Luck!
我最终将原始代码替换为 PageViewController 代码。其中的示例来自 Erica Sadun 的新书:“iOS5 Developer's Cookbook” .. 这本书将是 于 11 月 14 日发布,但 代码示例可供预购买者使用。
I ended up switching out my original code for PageViewController code. The samples from that are from Erica Sadun's new book: "iOS5 Developer's Cookbook" .. The book will be published on Nov. 14 but the code samples are available to pre-purchasers..