我有一个奇怪的错误,当动画的几个视图在iOS中。我的目标是从自定义的“拆分视图”切换。你可以在youtube上的视频中看到正在发生的事情:http://youtu.be/ZWbf2bQYMns
您可以在UIImageView的Y值中看到奇怪的“凹凸”,我一直在想如何修复它很长时间了。
这是View Controller的界面:
@interface VideoSharing_Pad : UIViewController
{
IBOutlet UIView *videoCallView;
IBOutlet UIImageView *imageView; //This is "inside" mediaView
IBOutlet UIView *mediaView;
CGRect mediaRect;
CGRect videoCallRect;
CGRect imageRect;
}在viewDidLoad中,我存储两个视图,执行以下操作:
//Get frames from XIB
mediaRect = mediaView.frame;
videoCallRect = videoCallView.frame;
imageRect = imageView.frame;这是当我想要从拆分视图切换到全屏模式时执行的代码:
- (IBAction)toggleFullScreen:(id)sender
{
if (iScreenMode == callAndShareMedia) {
CGRect fullScreenRect = CGRectMake(0, 0, 1024, 768);
CGRect dissapearRect = CGRectMake(0, - videoCallView.bounds.size.height, videoCallView.bounds.size.width, videoCallView.bounds.size.height);
[UIView animateWithDuration:1.0
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^{
[videoCallView setFrame:dissapearRect];
[imageView setFrame:fullScreenRect];
[mediaView setFrame:fullScreenRect];
}
completion:^(BOOL finished){
}];
iScreenMode = onlyShareMedia;
return;
}
else if (iScreenMode == onlyShareMedia)
{
[UIView animateWithDuration:1.0
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^{
[videoCallView setFrame:videoCallRect];
[mediaView setFrame:mediaRect];
[imageView setFrame:imageRect];
}
completion:^(BOOL finished){
}];
iScreenMode = callAndShareMedia;
return;
}
}如果能得到任何帮助,我将不胜感激。非常感谢!
这是XIB的屏幕截图:

正如您从屏幕截图和.h文件中看到的,imageView位于名为mediaView的UIView中,另一个UIView videoCallView包含三个虚拟图片。
发布于 2012-02-01 00:16:52
这确实是个有趣的问题。这肯定与同时设置superview和subview的动画有关。我做了示例程序,并重现了类似的情况。
我的变通办法是避免动画超级视图(mediaView),而只将子视图(imageView)展开为全矩形。既然你的超级视图(mediaView)没有太多,它不应该提供如此不同的用户体验。
因此,不是
[UIView animateWithDuration:1.0
delay:0.1
options: UIViewAnimationOptionCurveEaseOut
animations:^{
[videoCallView setFrame:dissapearRect];
[imageView setFrame:fullScreenRect];
[mediaView setFrame:fullScreenRect];
}];你可以做到
[UIView animateWithDuration:1.0
delay:0.1
options: UIViewAnimationOptionCurveEaseOut
animations:^{
[videoCallView setFrame:dissapearRect];
[imageView setFrame:(CGRect){fullScreenRect.origin.x - mediaRect.origin.x, fullScreenRect.origin.y - mediaRect.origin.y, fullScreenRect.size}];
}];要返回到正常模式,您可以忽略mediaView动画。您可能还希望将toggleButton与其他动画一起移动(设置动画)。
@jrturton的答案(第二部分)似乎是一个很好的变通方法,但它在我的示例代码上不起作用。它在前进的路上(扩张)起作用了,但在回来的路上(收缩),原因我不知道为什么。但不要因为我的评论而忽视他的回答,那可能是我。
https://stackoverflow.com/questions/9068964
复制相似问题