iphone - 当 iPad 方向改变时,UIView 动画行为异常

标签 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 commitAnimations];

现在的问题是,当我向左横向旋转 ipad 时,它的行为很奇怪,如果我给出条件是否向左横向而不是 UIViewAnimationTransitionCurlDown,动画仍然与向右横向旋转时的动画不一样

最佳答案

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

当你在横向模式下“卷起”时,点击右边的按钮,页面开始从右上翻到左下(意思是,你用右手翻页,然后向书的左边。也意味着书的装订在左边)。

当你做同样的事情,但按钮在左边时,动画不会旋转,即使正确旋转内容,在 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;
}

关于iphone - 当 iPad 方向改变时,UIView 动画行为异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3976579/

相关文章:

objective-c - 无法打开错误 "MainStoryboard_iPhone.storyboard"。第 126 行 : PCDATA invalid Char value 3

ios - 如何使用手势

iphone - UITextView 中的下划线/粗体

iphone - NSDictionary中的错误

ios - 动态行高和 sizeWithAttributes 警告

iphone - 如何为 iPhone OpenGL ES 渲染交互式地球仪?

iphone - 向上或向下滚动时UITableview崩溃以及如何为每个单元格设置水平 ScrollView

iphone - cocos2d CCSprite 碰撞问题

javascript - Mobile Safari - "touchend"事件在最后一次触摸被移除时没有触发?

ios - UIPageViewController 在旋转时不调整其 subview Controller 的大小