[英]How to swipe more then 3 UIViews on one ViewController?
我想使用滑动Gesture在一个视图控制器上滑动3个以上的视图。我在Objective-C上较新。 下面的代码是只刷3个视图,我想按顺序刷更多视图
- (void)ViewDidLoad
{
// creating custom First view and adding on view
firstFiveQuesView=[[UIView alloc]init];
firstFiveQuesView.frame=CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+54, self.view.frame.size.height, self.view.frame.size.width);
firstFiveQuesView.backgroundColor=[UIColor brownColor];
[self.view addSubview:firstFiveQuesView];
UILabel *Q1Label=[[UILabel alloc]init];
Q1Label.frame=CGRectMake(firstFiveQuesView.frame.origin.x+20, firstFiveQuesView.frame.origin.y,400, 20);
Q1Label.backgroundColor=[UIColor grayColor];
Q1Label.text=@"Q1: qqewuiqy qoeyq ooghj qyouiye o y";
[firstFiveQuesView addSubview: Q1Label];
// similarly second view created and added on main view...
// similarly third view created and added on main view...
// Swipe Gesture adding on the views
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
// Setting the swipe direction.
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[firstFiveQuesView addGestureRecognizer:swipeLeft];
[thirdFiveQuesView addGestureRecognizer:swipeRight];
}
// swipe left or right below
- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe
{
// What we do write now:here
if (swipe.direction == UISwipeGestureRecognizerDirectionLeft)
{
NSLog(@"Left Swipe");
}
if (swipe.direction == UISwipeGestureRecognizerDirectionRight)
{
NSLog(@"Right Swipe");
}
}
请帮我一些样品和教程
提前致谢.....................
最好将这三个视图添加到一个scrollView中,并相应地设置contentOffset。这样就可以避免添加手势。
在带有页面控制器的uiscrollView
使用3个视图
您可以使用称为PageViewController
的类来执行此操作。
此链接肯定会帮助您。
http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.