我有一个 UIView 子类,其中有一个 UIScrollView 作为成员。
我为 UIView 的大小调整设置动画并使用它调整 ScrollView 的大小。 UIScrollView 是一个无限的图片库(即 3 个 View ,在分页发生时交换内容)
[UIView animateWithDuration: ...
当我为代码设置动画时,在我的动画 block 中
myView.frame = someNewFrame;
我认为动画会在动画时插入中间帧大小。即在动画的每一帧期间进行调用:
[myView setFrame: someIntermediateFrame];
所以我覆盖了 myView 的 setFrame 方法:
-(void)setFrame:(CGRect)frame
{
[super setFrame:frame];
[self resizeSubviews];
}
- (void)resizeSubviews
{
CGRect frame = self.bounds;
scrollView.frame = frame;
scrollView.contentSize = CGSizeMake(frame.size.width * 3.0, frame.size.height); // 3 pages
[scrollView setContentOffset:CGPointMake(frame.size.width, 0.0) animated:NO]; // set contentOffset to middlePage
[scrollView setNeedsDisplay]; // just in case. don't know if this is necessary. Currently not helpful.
frame.origin.x = 0.0;
frame.origin.y = 0.0;
pageZeroRect = frame;
self.pageZero.frame = frame;
frame.origin.x += frame.size.width;
pageOneRect = frame;
self.pageOne.frame = frame;
frame.origin.x += frame.size.width;
pageTwoRect = frame;
self.pageTwo.frame = frame;
}
除了包含 View 之外没有动画发生。 ScrollView (和 subview )只是跳到它的最终值。
知道出了什么问题吗?它只是没有意义。一切看起来都很好,但一定有其他一些我不知道的事情在幕后发生。我从事 iOS 编程已有 1.5 年了,所以不是特别有经验,但也不是那么笨。
最佳答案
我在一年后看这个问题,一年后我更聪明了,我认为答案是覆盖我的 UIView 子类的 layoutSubviews。
或将 UIView 的 autoresizeSubviews 属性设置为 YES,并设置 subview 的正确自动调整掩码。
关于ios - 在调整 scrollView 的框架大小时,UIScrollView subview 的大小调整不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8012852/