【发布时间】:2016-07-10 21:21:10
【问题描述】:
我只在代码中创建视图控制器,没有 .xib 或情节提要。 我在视图中添加了许多其他子视图,它们是在 (void)loadView 方法中添加的,它们的框架在 (id)init 方法中初始化,如下所示
-(id)init{
bottomClinkRect = CGRectMake(playersBoardRect.origin.x + (playersBoardWidth * 0.320),
playersBoardRect.origin.y + playersBoardHeight - playerBottomImageRect.size.height - (playersBoardHeight * 0.038),
playersBoardWidth * 0.680,
playersBoardHeight * 0.038);
}
- (void)loadView {
bottomClink = [[UIScrollView alloc]initWithFrame:bottomClinkRect];
[bottomClink setScrollEnabled:YES];
bottomClink.contentSize = CGSizeMake(bottomClink.frame.size.height,bottomClink.frame.size.height);
[contentView addSubview:bottomClink];
}
我创建了空的滚动视图,然后根据屏幕上的用户操作,我尝试使用以下方法每次将一个 imageView 添加到滚动视图:
-(void)reloadCollections:(NSNotification *)notification
{
UIImage *latestPieceCaptured = [gameController capturedBlackPiecesImages].lastObject;
[whitePlayerCaptures addObject:latestPieceCaptured];
NSInteger newNumberOfViews = whitePlayerCaptures.count;
CGFloat xOrigin = (newNumberOfViews - 1) * bottomClink.frame.size.height;
CGRect imageRect = CGRectMake(bottomClink.frame.origin.x + xOrigin,
bottomClink.frame.origin.y,
bottomClink.frame.size.height, //the width is taken from the height
bottomClink.frame.size.height); // the height
UIImageView *image = [[UIImageView alloc] initWithFrame:imageRect];
image.backgroundColor = [UIColor blackColor];
image.image = latestPieceCaptured;
image.contentMode = UIViewContentModeScaleAspectFit;
//set the scroll view content size
bottomClink.contentSize = CGSizeMake(bottomClink.frame.size.height * newNumberOfViews,
bottomClink.frame.size.height);
[bottomClink addSubview:image];
}
我的问题是 scrollview 被添加到主 view 但 imageview(s) 没有出现。
我已经对其进行了调试,scrollview 添加了子视图,它们具有帧大小等所有内容,但未显示在屏幕上。我尝试了很多变化,但到目前为止没有任何效果。
提前感谢您提供任何链接或建议。
【问题讨论】:
标签: ios objective-c uiscrollview uiimageview addsubview