【问题标题】:iPhone: TableView inside UIScrollview, show vaccillating scrollbars aroundiPhone:UIScrollview 内的 TableView,显示摇摆不定的滚动条
【发布时间】:2010-04-26 08:10:40
【问题描述】:

我在滚动视图中添加了一些表格和其他视图。在表格中滚动工作正常。但是在父滚动视图中,滚动时会显示一个摇摆不定的垂直滚动条,有时甚至会到屏幕中间。有时显示在屏幕的左侧。并且不限于垂直滚动条区域。当我设置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];

}

【问题讨论】:

    标签: iphone uiscrollview


    【解决方案1】:

    请记住,滚动条也是滚动的子视图。在对视图进行操作之前将其从 views 数组中排除。

    【讨论】:

      【解决方案2】:

      嗯。这解决了我的问题。滚动条似乎是一种 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];
      

      }

      【讨论】:

        猜你喜欢
        • 2021-10-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-23
        • 2011-01-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多