2011-11-04 81 views
1

我有一个UIScrollView作为成员的UIView子类。在调整scrollView的框架大小时调整UIScrollView子视图的大小不正确

我为UIView调整大小并使用它调整滚动视图的大小。所述的UIScrollView是一个无限的图片库(即,3次,作为寻呼发生进出交换内容)

[UIView animateWithDuration: ... 

当我动画的代码,在动画块I有

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; 
} 

否动画出现比含有视图其他。 scrollview(和子视图)只是跳到它的最终值。

任何想法发生了什么问题?这只是没有意义。一切都看起来不错,但是我不知道有什么其他的东西在引擎盖下发生。我已经对iOS进行了1.5年的编程,所以我没有超级经验,但也不是那么愚蠢。

回答

1

我在一年后看到这个问题,一年更聪明,并会认为答案是重写我的UIView子类的layoutSubviews。

或将UIView的autoresizeSubviews属性设置为YES,并设置子视图的正确自动识别掩码。

0

您是否尝试不覆盖setFrame方法?

如果它不工作,那么尝试设置动画块中所有子视图的最终帧。