我有一个ViewController
,ScrollView
包含来自IB
的一堆内容,但是滚动视图无效。
- (void)viewDidLoad
{
[super viewDidLoad];
/*
* configure a bunch of label, text ,images and views from IB
*/
UIScrollView* scrollView = (UIScrollView*)self.view;
scrollView.scrollEnabled = YES;
scrollView.contentSize = CGSizeMake(320, 2000);
}
我可以看到我的内容直到底部但无法滚动。如果它意味着什么,请ViewController
TabBar
答案 0 :(得分:2)
[self.view addSubView:scrollView];
这是一个例子
@interface ImageScrollView ()
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIPageControl *pageControl;
@end
-(void) baseInit {
// Scroll View - Full frame width
_scrollView = [[UIScrollView alloc] init];
_scrollView.frame = self.frame;
_scrollView.delegate = self;
// ImageView - Full frame width
CGFloat width = self.frame.size.width;
CGFloat height = self.frame.size.height;
int i = 0;
int count = [imagesArray count];
for (i = 0; i < count; i++) {
UIImage *image = [UIImage imageNamed:imagesArray[i]];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i * width, 0, width, height)];
[imageView setImage:image];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
imageView.tag = i+1;
[_scrollView addSubview:imageView];
}
[_scrollView setContentSize:CGSizeMake(count * width, height)];
[_scrollView setFrame:CGRectMake(0, 0, width, height)];
_scrollView.pagingEnabled = YES;
_scrollView.showsHorizontalScrollIndicator = NO;
pageControl.numberOfPages = count;
pageControl.currentPage = 0;
CGRect pageFrame = CGRectMake(5, 5, 50, 50);
pageControl.frame = pageFrame;
pageControl.backgroundColor = [UIColor redColor];
[self addSubview:_scrollView];
[_scrollView addSubview:pageControl];
}
不要忘记在视图中调用baseInit函数加载。 此示例无需在Storyboard或nib文件中添加任何对象