开发者

UIView Animation Misbehaves when iPad orientation is changed

I am using this code for UIView transition effect

[UIView beginAnimations: nil context: nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView commitAnimations];

Now the problem is that when i rotated the ipad in Landscape Left it behaves weird and if i give condition w开发者_StackOverflow社区hether if Landscape left than UIViewAnimationTransitionCurlDown, still the animation is not the same as it is during Landscape-right way


I've got the exact same issue. For people having hard time understanding the problem :

When you're doing "curl up" in landscape mode,with the button on the right, the page starts to flip from top right to bottom left (meaning, your turned the page with your right hand, and moved toward the left side of the book. also meaning that the book's binding is on the left).

When you're doing the very same, but with button on the left, the animation don't rotate, even when correctly rotating content, saying "shouldAutorotateToInterfaceOrientation : True" in the vc. As a result the animation goes from bottom left to top right, giving the impression that the book's binding now is on the right.

Some code to illustrate that :

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self)
    {
        view1 = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
        [view1 setBackgroundColor:[UIColor greenColor]];
        [view1 setFont:[UIFont systemFontOfSize:80]];
        [view1 setText:@"VIEW 1"];

        view2 = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
        [view2 setBackgroundColor:[UIColor redColor]];
        [view2 setFont:[UIFont systemFontOfSize:80]];
        [view2 setText:@"VIEW 2"];
    }
    return self;
}


-(void)didSwipeNext
{
    [self performSelector:@selector(swipePrevious) withObject:nil afterDelay:1];
}

-(void)didSwipePrevious
{
    [self performSelector:@selector(swipeNext) withObject:nil afterDelay:1];
}

-(void)swipeNext
{
    [UIView beginAnimations:@"curl" context:NULL];
    [UIView setAnimationDuration:1];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationBeginsFromCurrentState:NO];
    [UIView setAnimationDidStopSelector:@selector(didSwipeNext)];

    [view1 removeFromSuperview];
    [self.view addSubview:view2];

    [UIView commitAnimations];
}

-(void)swipePrevious
{

    [UIView beginAnimations:@"curl" context:NULL];
    [UIView setAnimationDuration:1];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationBeginsFromCurrentState:NO];
    [UIView setAnimationDidStopSelector:@selector(didSwipePrevious)];

    [view2 removeFromSuperview];
    [self.view addSubview:view1];

    [UIView commitAnimations];
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:view1];
    [self performSelector:@selector(swipeNext) withObject:nil afterDelay:1];
}


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}


Have you tried using:

[UIView setAnimationBeginsFromCurrentState:NO];

If you start an animation during a rotation change and that value is set to YES, it may use the UIView's frame when the coordinates are inverted.

You can use the methods willAnimateRotationToInterfaceOrientation and didAnimateRotationToInterfaceOrientation to stop the animation before the rotation, and resume it after.


Ben G's clearly explained the problem. I've found a workaround but didn't know the underlying reason. My workaround is here: UIViewAnimationOptionTransitionCurlUp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜