我在滚动视图中有两个UIView,其中两个视图都有自动布局关闭的子视图
- MainView
- ScrollView
- UIView
-UIButtons
-UIButtons
- UIView
- Navigation Bar
- UIImageView
- UIImageView
ScrollView
下的第一个UIView
具有UIButtons
,它将是动态的,这取决于我想要设置第二视图的高度和位置。
比如说,如果有三个按钮,那么下一个CCD_ 4应该从w.r.t下降到第一个UIView
的高度。
在试图实现这一点的同时,我无法在运行时设置UIView
的高度?
编辑:这是我正在做的我正在改变滚动视图的内容大小:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// CGRect frame = self.myGamesSection.frame;
// frame.size.height = 100.0f;
// self.myGamesSection.frame = frame;
}
-(void) viewDidAppear:(BOOL)animated {
CGSize rSize = CGSizeMake(320.0f,1200.0f);
self.scrollView.contentSize = rSize;
}
-(void) viewWillAppear:(BOOL)animated {
CGSize rSizeMyGames = CGSizeMake(320.0f,100.0f);
self.myGamesSection.frame = CGRectMake(0,47,320, 100);
}
在UIView
上添加UIScrollView
,然后添加按钮。不需要根据您的按钮大小更改scrollView
的contentSize
。
上次我遇到类似的问题时,当滚动视图的内容大小在运行时发生变化时,我只是切换到UITableView而不是UIScrollView,在那里,您可以始终在委托的方法heightForRowAtIndexPath:中指定单元格高度,并在每次更改时将reloadData发送到tableView。也许这不是最好的解决方案,但它是有效的。
您可以使用这种类型的逻辑。。。
//Keep a variable which hold your yOffsetPositon and loop to add buttons. After that set the height of view.
int yPos = 0;
UIView *firstView = [[UIView alloc] initWithFrame:frame];
for (int =i =0; i<10; i++){
UIButton *b = [[UIButton alloc] initWithFrame:CGRectMake(0,yPos,30,30)];
yPos+=30;
//if you want spacing
//yPos+=10;
}
//reset height of firstView
fistView.frame = CGRectMake(frame.origin.x,frame.origin.y,yPos,frame.size.width);
//Set height of second view
UIView *secondView = [[UIView alloc] initWithFrame:CGRectMake(0,firstView.frame.size.height+10,HEIGHT,Width)];