您好,我与UIScrollView有一个问题,我希望有人能帮助我。
我在视图中心有一个700x580像素的UIView,我添加了一个350x580像素的UIScrollview。在这个scrollView中,我将10个subViews放在一起,然后将scrollview上的属性clipsToBounds设置为NO,这样我就可以看到scrollView的subViews不在scrollView中。现在我的问题是scrollView的subviews也显示在UIView的外面。有什么原因要禁用它吗?
下面是我的问题的示例代码
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 700, 580)];
CGFloat viewDisdance = 50;
UIScrollView *theScrollView = [[UIScrollView alloc]
initWithFrame:CGRectMake((myView.frame.size.width-350)/2, // X
0, // Y
350+viewDisdance, // with
580)]; // height
theScrollView.backgroundColor = [UIColor blueColor];
theScrollView.clipsToBounds = NO;
theScrollView.pagingEnabled = YES;
[myView addSubview:theScrollView];
CGFloat offset = 0.0;
for (NSInteger i = 0; i<10; i++) {
UIView *aSubView = [[UIView alloc] initWithFrame:CGRectMake(offset, 0, 350, 580)];
aSubView.backgroundColor = [self randomColor]; //a method that givs me a random color back
offset += aSubView.frame.size.width;
offset += viewDisdance;
[theScrollView addSubview:aSubView];
}
[window addSubview:myView];下面是此代码示例结果的屏幕

http://img18.imageshack.us/i/bildschirmfoto20110104u.png/
红色区域为myView
蓝色区域为theScrollView
其他颜色区域是theScrollView的subViews
发布于 2011-01-04 17:14:06
你能试试myView.clipsToBounds = YES;吗?
https://stackoverflow.com/questions/4591982
复制相似问题