1

AUIScrollView包含 5UIView秒。基本上我想展开和折叠它们,当用户触摸任何一个UIView.

动画globalPressReleasesView展开代码:

            [UIView beginAnimations:@"Expand" context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationDelegate:self];

                                [globalPressReleasesView setFrame:CGRectMake(globalPressReleasesView.frame.origin.x, globalPressReleasesView.frame.origin.y, globalPressReleasesView.frame.size.width, globalPressReleasesView.frame.size.height + [globalPressReleasesArray count]*105)];

                                [financialPressReleasesView setFrame:CGRectMake(financialPressReleasesView.frame.origin.x, financialPressReleasesView.frame.origin.y + [globalPressReleasesArray count]*105, financialPressReleasesView.frame.size.width, financialPressReleasesView.frame.size.height)];


                                [newOnCscView setFrame:CGRectMake(newOnCscView.frame.origin.x, newOnCscView.frame.origin.y + [globalPressReleasesArray count]*105, newOnCscView.frame.size.width, newOnCscView.frame.size.height)];

                                [latestEventsView setFrame:CGRectMake(latestEventsView.frame.origin.x, latestEventsView.frame.origin.y + [globalPressReleasesArray count]*105, latestEventsView.frame.size.width, latestEventsView.frame.size.height)];

                                [latestCaseStudiesView setFrame:CGRectMake(latestCaseStudiesView.frame.origin.x, latestCaseStudiesView.frame.origin.y + [globalPressReleasesArray count]*105, latestCaseStudiesView.frame.size.width, latestCaseStudiesView.frame.size.height)];

                                [scrollView setContentSize:CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height + [globalPressReleasesArray count]*105)];

            [UIView commitAnimations];

其他xib属性:

每个UIView剪辑 scrollview.autoresize = YES

问题:

'globalPressReleasesView' 完美扩展,但是当我滚动我的scrollview. globalPressReleasesViewframe 将自身重置为 xib 中定义的原始帧值。

有人能猜出问题是什么吗?

4

1 回答 1

3

首先,让我们稍微简化一下代码:

CGFloat heightDifference = [globalPressReleasesArray count] * 105.0f;

CGRect globalPressReleasesViewFrame = globalPressReleasesView.frame;
globalPressReleasesViewFrame.size.height += heightDifference;
globalPressReleasesView.frame = globalPressReleasesViewFrame;

NSArray* movedViews = @[financialPressReleasesView, newOnCscView, latestEventsView, latestCaseStudiesView];

for (UIView* movedView in movedViews) {
   CGRect movedViewFrame = movedView.frame;
   movedViewFrame.origin.y += heightDifference;
   movedView.frame = movedViewFrame
}

CGSize contentSize = scrollView.frame.size;
contentSize.height += heightDifference;
[scrollView setContentSize:contentSize];

现在很清楚代码的作用。

该代码似乎是绝对正确的。我建议您检查设置帧的值(NSLog或断点)。

Note there are only two ways a view frame can be changed. 1. You change it in code 2. It's autoresized because you have changed it's ancestor's frame (or when the user's switches portrait/landscape mode).

于 2013-03-29T15:29:44.417 回答