Iphone 更改iPad方向时,UIView动画会出现错误行为

Iphone 更改iPad方向时,UIView动画会出现错误行为,iphone,objective-c,ipad,Iphone,Objective C,Ipad,我使用此代码来实现UIView转换效果 [UIView beginAnimations: nil context: nil]; [UIView setAnimationDuration:1.0]; [UIView setAnimationBeginsFromCurrentState:YES]; [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES]; [UIView c

我使用此代码来实现UIView转换效果

[UIView beginAnimations: nil context: nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView commitAnimations];
现在的问题是,当我在横向向左旋转ipad时,它的行为很奇怪,如果我给出条件,如果横向向左,而不是UIViewAnimationTransitionCurlDown,动画仍然与横向向右旋转时的动画不同

您是否尝试过使用:

[UIView setAnimationBeginsFromCurrentState:NO];
如果在旋转更改期间启动动画,并且该值设置为“是”,则在坐标反转时可能会使用UIView的帧


您可以使用WillAnimateRotationInterfaceOrientation和DidAnimateRotationInterfaceOrientation方法在旋转之前停止动画,然后在旋转之后继续。

我遇到了完全相同的问题。 对于难以理解问题的人:

当你在横向模式下“卷曲”时,按下右边的按钮,页面开始从右上角翻转到左下角(这意味着你用右手翻过页面,然后移到书的左边。也意味着书的装订在左边)

当您执行同样的操作时,但使用左侧的按钮,动画不会旋转,即使正确旋转内容,在vc中说“shouldAutorotateToInterfaceOrientation:True”。因此,动画从左下角转到右上角,给人的印象是,书籍的装订现在位于右侧

一些代码可以说明:

- (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;
}

Ben G清楚地解释了这个问题。我找到了解决办法,但不知道根本原因。我的解决方法是:

什么是“行为怪异”?它的动画是颠倒的动画与它的横向动画不同,对吗