我正在使用 UIView transitionFromView 在两个视图之间切换。我目前正在 UIView 子类中执行以下操作:
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img.png"]];
imgView.frame = CGRectMake(0, 0, 100, 100);
UIView *detailView = [[UIView alloc] initWithFrame:imgView.frame];
detailView.backgroundColor = [UIColor redColor];
detailView.frame = imgView.frame;
[self addSubview:imgView];
[UIView transitionFromView:imgView toView:detailView duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished){
}
];
这按预期工作。过渡按其应有的方式执行。问题是我需要在包含先前代码的视图的子视图中进行转换。所以,我把所有东西都放在一个容器中,并尝试对其进行动画处理:
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img.png"]];
imgView.frame = CGRectMake(0, 0, 100, 100);
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
UIView *detailView = [[UIView alloc] initWithFrame:imgView.frame];
detailView.backgroundColor = [UIColor redColor];
detailView.frame = imgView.frame;
[container addSubview:imgView];
[self addSubview:container];
[UIView transitionFromView:imgView toView:detailView duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished){
}
];
但在这种情况下,动画不会运行。相反,我只看到没有过渡的最终结果。谁能帮我弄清楚这两种情况有何不同?
这里描述了同样的问题,但我认为现有的“解决方案”不足以完全描述这种行为。 使用 transitionFromView 和 transitionWithView 的过渡行为