如何在一个ViewController上滑动3个以上的UIViews?

时间:2014-06-25 12:47:35

标签: ios objective-c uiview uiswipegesturerecognizer uiviewanimationtransition

我想使用滑动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");
    }
}

请帮我一些示例和教程

提前致谢.....................

3 个答案:

答案 0 :(得分:0)

最好将这3个视图添加到一个scrollView中并相应地设置contentOffset。然后你可以避免添加手势。

答案 1 :(得分:0)

使用页面控制器{/ 1>在uiscrollView中使用3个视图

答案 2 :(得分:0)

您可以使用名为PageViewController的类来执行此操作。

此链接一定会帮助您。

http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial