i want to swipe more than 3 views on one view controller using swipe Gesture.i am fresher on objective-c. this below code is to swipe 3 views only i want to swipe more views in sequence
- (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");
}
}
please help me with some samples and tutorials
Thanks in advance.....................
最好将这三个视图添加到一个scrollView中,并相应地设置contentOffset。这样就可以避免添加手势。
在带有页面控制器的uiscrollView
使用3个视图
You can do this using a class called PageViewController
.
This link should surely help you out.
http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.