gpt4 book ai didi

ios - UIView 框架在滚动时自动重置

转载 作者:行者123 更新时间:2023-12-01 19:12:17 25 4
gpt4 key购买 nike

一个 UIScrollView包含 5 UIView s。基本上,当用户触摸 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 时. globalPressReleasesView frame 将自身重置为 xib 中定义的原始帧值。

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

最佳答案

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

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 或断点)。

请注意,只有两种方式可以更改 View 框架。
1.你在代码中改变它
2. 它是自动调整大小的,因为你改变了它的祖先框架(或者当用户切换纵向/横向模式时)。

关于ios - UIView 框架在滚动时自动重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15703884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com