animationUIView框架,子视图UIScrollView并不总是animation
在这个例子中。
当我为tabBarController设置animation效果(用于全屏效果)时,我正在animationPhotoViewerViewController的框架。 PhotoViewer使用uiscrollview生成苹果的照片应用程序所具有的同样的效果。 无论出于什么原因,有时它会随着我的PhotoViewer框架一起animation,有时它不会。
您可以在第一个示例中看到在增加帧大小时跳转,但在减小帧大小(并恢复标签栏)时可以很好地进行animation处理。
但是在这个例子中,当照片是垂直的时候,它会在两个方向上跳跃。
在这两种情况下,如果我使用滚动视图放大照片,它将在两个方向上正确animation。
我知道有证据,但是我不能把手指放在这里发生的事情上。
这是我的animation块:
void (^updateProperties) (void) = ^ { self.navigationController.navigationBar.alpha = hidden ? 0.0f : 1.0f; self.navigationController.toolbar.alpha = hidden ? 0.0f : 1.0f; if (self.tabBarController) { int height = self.tabBarController.tabBar.bounds.size.height; for(UIView *view in self.tabBarController.view.subviews) { int newHeight; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (UIInterfaceOrientationIsPortrait(orientation)) { newHeight = hidden ? [[UIScreen mainScreen] bounds].size.height : [[UIScreen mainScreen] bounds].size.height - height; } else { newHeight = hidden ? [[UIScreen mainScreen] bounds].size.width : [[UIScreen mainScreen] bounds].size.width - height; } if([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, newHeight, view.frame.size.width, view.frame.size.height)]; } else { CGRect newFrame = CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, newHeight); [view setFrame:newFrame]; // update our VC frame with animation [self.view setFrame:newFrame]; } } } };
代码改编自SO: UITabBar上的post不会隐藏
github上的完整源代码。
一般来说,如果animation有时起作用,有时不起作用,那是因为在后一种情况下,延迟执行是通过将相关属性设置为其最终值而被有效取消。
在UIScrollView
的特殊情况下,经常会发生这样的情况,即在animation块closures后,调用-layoutSubviews
而不animation一个运行循环。 由于这个原因,我通常尝试避免在视图层次结构中使用UIScrollView
方法进行布局(因为特别是在iOS 5之前, UIScrollView
真的是触发器,因此需要布局)。
我build议从-layoutSubviews
删除对-[EGOPhotoImageView layoutScrollViewAnimated:]
的-layoutSubviews
,并将其添加到覆盖的-setFrame:
取而代之。
如果您可以定位iOS4或更高版本,请查看UIViewAnimationOptionLayoutSubviews
。 使用基于块的animation作为选项可能只是在不改变其他任何东西的情况下工作。
我试着在iPad 4.2和4.3模拟器上的github代码,它工作正常…没有图像调整任何大小! 可能有一些版本问题。 此外,我试图改变你的animation块,以下服务相同的目的:
void (^updateProperties) (void) = ^ { self.navigationController.navigationBar.alpha = hidden ? 0.0f : 1.0f; self.navigationController.toolbar.alpha = hidden ? 0.0f : 1.0f; }
让我知道如果我失去了一些东西:)