我有滚动视图,其中子视图是从底部添加的,例如在墙上添加砖块(在我的情况下只有一块砖块),然后在其上添加下一块砖块,依此类推。与 default 一样UIScrollView ContentSize
,滚动将发生在顶部。我怎样才能滚动到底部。如果我向下滚动,我应该能够看到其他的积木,它们一个接一个地添加。
正如您在下面的屏幕截图中看到的那样,开始按钮应该向下而不是向上。
非常感谢任何形式的帮助。
谢谢
示例代码:
CGFloat initialYPoint = 30;
for (OUSTLevel* currentLevel in self.course.sortedLevelsList) {
NSArray* nibList = [[UINib nibWithNibName:@"OUSTLearningMapPlayLevelCell" bundle:nil] instantiateWithOwner:self options:nil];
OUSTLearningMapPlayLevelCell* playLevelCell = nil;
for (UIView* childView in nibList) {
if ([childView isKindOfClass:[OUSTLearningMapPlayLevelCell class]]) {
playLevelCell = (OUSTLearningMapPlayLevelCell*)childView;
break;
}
}
CGFloat cellHeight = CGRectGetHeight(playLevelCell.frame);
CGFloat yPoint = CGRectGetHeight(self.scrollview.frame) - (cellHeight + initialYPoint);
CGRect cellFrame = CGRectMake(0, yPoint, viewWidth, cellHeight);
[playLevelCell setFrame:cellFrame];
[self.scrollview addSubview:playLevelCell];
initialYPoint += cellHeight;
if (!landingNodeLevelData.locked) {
[playLevelCell.unlockedView setHidden:NO];
[playLevelCell.lockedView setHidden:YES];
// Frame calculation for placing pin
CGFloat centerPoint = playLevelCell.unlockedView.frame.size.width / 4;
pinXPoint = centerPoint + 5;
pinYPoint = yPoint - 30;
}
}
CGRect pinFrame = CGRectMake(pinXPoint, pinYPoint, 80, 80);
[self.pinImageView setFrame:pinFrame];
[self.scrollview addSubview:self.pinImageView];
[self.view bringSubviewToFront:self.pinImageView];
self.scrollview.contentSize = CGSizeMake(self.view.frame.size.width, initialYPoint);
self.scrollview.contentInset = UIEdgeInsetsMake(30.0, 0.0, 30.0, 0.0);
CGPoint bottomOffset = CGPointMake(0, self.scrollview.contentSize.height - self.scrollview.bounds.size.height+ 30);
编辑:我没有使用约束布局,我正在计算和设置框架。