我有一个奇怪的错误,当动画的几个视图在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的答案(第二部分)似乎是一个很好的变通方法,但它在我的示例代码上不起作用。它在前进的路上(扩张)起作用了,但在回来的路上(收缩),原因我不知道为什么。但不要因为我的评论而忽视他的回答,那可能是我。
发布于 2012-01-31 16:57:48
这个问题很有趣。我不能从工作中观看你的视频,但我希望你的问题是,在动画过程中,你正在调整视图及其子视图的大小,可能会有来自任何自动调整大小蒙版的干扰(你有吗?)-超级视图将更改子视图的大小,然后将应用内插帧。
如果你想一想,也会有一个阶段,在那里你的图像视图必须比superview更快地动画,因为它有更多的地面要覆盖,以达到相同的最终矩形。由动画计算出的插值可能会与此作斗争。
如果移除任何自动调整遮罩大小都不起作用,则可能需要将动画一分为二-一个用于增加superview的大小,另一个用于将图像视图缩放到完整大小。
https://stackoverflow.com/questions/9068964
复制相似问题