Creating View Transitions Similar to Kindle App
I'm pretty up to speed with Objective C and IOS development, but I haven't done any animations (short of animated:YES sorts of things).
I'd like some advice on how to develop a page transition similar to that used in the Amazon Kindle App. When reading a book in t开发者_运维问答he Kindle app, a swipe left or right 'turns' the page. The page turn is indicated by the current page sliding to the right or left, and the new page coming in from the left or right. It's a good visual indication of what's going on without being overly flashy. Interestingly, if you dont swipe far enough, the current page snaps back into position. Not sure I need that part, though.
The view in question is a UIWebView. I'm assuming I could craete another UIWebView, populate its content as needed, and animate the transition between the two. Just not sure how to do that.
I'm coding for IOS 4 and above.
Thank you
I am making a similiar thing in my application. Look at my code responsible for handling long press gesture ( it could be swiping as well ) :
float startX;
float displacement;
-(IBAction)handleLongPressGesture:(UILongPressGestureRecognizer *)sender
{
float nowX;
if ( sender.state == UIGestureRecognizerStateBegan )
{
startX = [sender locationInView:mainWidgetView].x;
}
if ( sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateCancelled)
{
if ( abs(displacement) > PIXELS_TO_MOVE )
{
if ( displacement > 0 )
[self moveLeft];
else if ( displacement < 0 )
[self moveRight ];
}
else
{
[self moveWebViewsToOriginalPositions];
}
return;
}
nowX = [sender locationInView:mainWidgetView].x;
displacement = nowX - startX;
if ( (displacement > 0 && slider.currentPage == 0) || (displacement < 0 && slider.currentPage == slider.numberOfPages -1 ) )
{
return;
}
[self moveWebViewsBy:displacement];
}
-(void)moveWebViewsBy:(float)dx
{
for (int i = 0; i<3 ; i ++)
{
float oldDx = [ mainWidgetManager originalPositionForWebView:i ] ;
//float oldDy = mainWebViews[i].layer.position.y;
float oldDy = 425/2;
[mainWebViews[i].layer setPosition:CGPointMake(oldDx+dx, oldDy)];
}
}
-(void)moveWebViewsToOriginalPositions
{
[UIView animateWithDuration:0.4
delay:0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
for (int i = 0; i<3 ; i ++)
{
float oldDx = [ mainWidgetManager originalPositionForWebView:i ] ;
//float oldDy = mainWebViews[i].layer.position.y;
float oldDy = 425/2;
[mainWebViews[i].layer setPosition:CGPointMake(oldDx, oldDy)];
}
}
completion:nil];
}
Let me know if you need any help with that. I can show you code responsible for swiping if you want.
精彩评论