我正在开发笑话应用程序,但我仍然缺少一个功能,即显示笑话文本视图的方式与在 Iphone 中显示照片的方式相同,并让用户从右向左滑动手指,反之亦然:
有没有人有一个例子或知道一个?
我正在开发笑话应用程序,但我仍然缺少一个功能,即显示笑话文本视图的方式与在 Iphone 中显示照片的方式相同,并让用户从右向左滑动手指,反之亦然:
有没有人有一个例子或知道一个?
执行此操作以检测滑动:
UISwipeGestureRecognizer *swipeLeftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
swipeLeftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
UISwipeGestureRecognizer *swipeRightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
swipeLeftRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
// 将其添加到您想要的视图中
[self.view addGestureRecognizer:swipeLeftRecognizer];
[self.view addGestureRecognizer:swipeRightRecognizer];
//处理程序代码:
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
//do something when swiped left.
}
else if (recognizer.direction == UISwipeGestureRecognizerDirectionRight)
{
//do something when swiped right.
}
}
UIPageViewController
如果我理解您的要求,您正在寻找。
设置 aUIPageViewController
非常简单。
UIPageViewController *pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
然后只需设置委托,并创建相应的委托方法,就可以了!
可以从UIPageViewController
的类引用中引用委托方法。
祝你好运!欢迎来到堆栈溢出!