当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - iPhone View Sliding effect - Beginner

问题描述:

What is the event in iPhone development to write code to a slide left and slide right operation.

As in when you slide the view of your phone, you go into another view. What is the event that i should write my code ?

网友答案:

Darvids0n covered a gesture to slide the view out. I interpreted the question as an animation to slide the view out, in which case you'll want UIView's transitionFromView:toView:duration:options:completion: class method:

[UIView transitionFromView:view1 toView:view2 duration:1.0 options:(UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionTransitionFlipFromLeft) completion:NULL];

This actually gives you a curl. If you want a slide, you'll have to code a custom animation. Check out UIView's documentation and especially the 'animateWithDuration:animations:' class method.

网友答案:

The event you are looking to catch is called a swipe. Apple provides a UISwipeGestureRecognizer class to handle this for you. Implementation advice can be found in the Gesture Recognizers section of the Event Handling Guide for iOS.

Briefly, you create the recognizer:

UISwipeGestureRecognizer *swipeGestureRecognizer =
[[[UISwipeGestureRecognizer alloc]
  initWithTarget:self action:@selector(swipe:)] autorelease];

Then set how many fingers the swipe is, and what direction it needs to be in:

swipeGestureRecognizer.numberOfTouchesRequired = 2; // default is 1
// allow swiping either left or right, default is right only
swipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft |
                                   UISwipeGestureRecognizerDirectionRight;

And then add it to your view:

[self.view addGestureRecognizer:swipeGestureRecognizer];

When the user swipes, your swipe: method will get called.

分享给朋友:
您可能感兴趣的文章:
随机阅读: