我将 UIScrollView 添加到我正在制作的可重用 View 中,然后将该可重用 View 添加到 UIViewController 中。
在我的可重用 View 中,我将 UIView 添加到 UIScrollView 中:
int yLocation = 20;
for (int i= 0 ; i < 5; i++) {
UIView *tempView = [[offerCell alloc]initWithDelegate:self];
tempView.frame = CGRectMake(5, yLocation, 290.0F, 70.0F);
yLocation += 90;
[self.scrollView addSubview:tempView];
UILabel *tempLabel = [tempView viewWithTag:1000];
tempLabel.text = [NSString stringWithFormat:@"Label Number %d" , i];
[tempLabel sizeThatFits:CGSizeMake(1000, 1000)];
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width, yLocation);
然后我将 UIView 添加到我的 UIViewController
UIView *tempView = [[BuyTokensView alloc] initWithDelegate:self andViewController:self];
[self.view addSubview:tempView];
CGPoint point = CGPointMake(10, 0);
tempView.center = point;
View 显示正确,但我无法滚动 UIScrollView。我的 UIScrollView 高度小于我在 ContentSize 中指定的高度,为什么我无法滚动?
这是 UIViewController 的图片:
最佳答案
您可以尝试禁用自动布局或使用本技术说明中的策略:
https://developer.apple.com/library/ios/technotes/tn2154/_index.html#//apple_ref/doc/uid/DTS40013309
关于ios - UIScrollView 不起作用(无法滚动),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20165704/