我已经在滚动视图中添加了一些表格和其他vies。在表格中滚动工作正常。但在父滚动视图中,当滚动时,会显示一个摇摆的垂直滚动条,有时甚至会出现在屏幕的中间。有时会在屏幕左侧显示。并且不限于垂直滚动条区域。当我设置showsVerticalScrollIndicator = NO时,它没有显示。但是你知道为什么滚动条要到处移动吗?
DashboardView是UIScrollView的一个子类。
dashboard=[[DashboardView alloc] initWithFrame:fullScreenRect];
dashboard.contentSize = CGSizeMake(320,700); // must do!
dashboard.showsVerticalScrollIndicator = YES;
dashboard.bounces = YES;
self.view = dashboard;
@implementation DashboardView
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect {
// Drawing code
}
- (void) layoutSubviews{
NSArray *views = self.subviews;
[UIView beginAnimations:@"CollapseExpand" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
UIView *view = [views objectAtIndex: 0];
CGRect rect = view.frame;
for (int i = 1; i < [views count]; i++ ) {
view = [views objectAtIndex:i];
view.frame = CGRectMake(rect.origin.x, rect.origin.y + rect.size.height, view.frame.size.width, view.frame.size.height);
rect = view.frame;
}
[UIView commitAnimations];
}发布于 2010-04-26 18:28:45
记住,scrollbars也是scroll的子视图。在对视图执行某些操作之前,将其从views数组中排除。
发布于 2010-05-04 19:36:13
是啊。这解决了我的问题。看起来Scrollbar是一种UIImageView。如果有人需要它,这是我的新代码,它工作得很好。
(void) layoutSubviews{
NSArray *views = self.subviews;
[UIView beginAnimations:@"CollapseExpand" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
//CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
// [self.view insertSubview:balanceView belowSubview:profileView];
UIView *view = [views objectAtIndex: 0];
CGRect rect = view.frame;
for (int i = 1; i < [views count]; i++ ) {
view = [views objectAtIndex:i];
if ([view isMemberOfClass: [UIView class] ]) {
//CFShow(view);
view.frame = CGRectMake(rect.origin.x, rect.origin.y + rect.size.height, view.frame.size.width, view.frame.size.height);
rect = view.frame;
}
}
[UIView commitAnimations];}
https://stackoverflow.com/questions/2711918
复制相似问题