Ios5 为什么使用UIScrollView';在iOS 4.3中,s滚动会触发layoutSubViews方法,但在5.0&;在上面

Ios5 为什么使用UIScrollView';在iOS 4.3中,s滚动会触发layoutSubViews方法,但在5.0&;在上面,ios5,uiscrollview,ios4,layoutsubviews,Ios5,Uiscrollview,Ios4,Layoutsubviews,我定制了UIView来创建自定义UI组件 视图的层次结构是这样的 ----自定义UIView ----------------UIScrollView -(id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if(self){ //Allocation and Initialization of ScrollView //... [super addSubView:scrollView]; } retur

我定制了UIView来创建自定义UI组件

视图的层次结构是这样的

----自定义UIView

----------------UIScrollView

-(id)initWithFrame:(CGRect)frame{

self = [super initWithFrame:frame];

if(self){

//Allocation and Initialization of ScrollView
//...
[super addSubView:scrollView];

}
return self;
}

- (void)layoutSubviews {

    DLog(@"%@",[NSThread callStackSymbols]);
    [super layoutSubviews];

    [self reloadData];

}

//This method can be used to reload the entire control
-(void)reloadData{
//Reload the subviews of control
}
-----------------------------ScrollView中的子视图

-(id)initWithFrame:(CGRect)frame{

self = [super initWithFrame:frame];

if(self){

//Allocation and Initialization of ScrollView
//...
[super addSubView:scrollView];

}
return self;
}

- (void)layoutSubviews {

    DLog(@"%@",[NSThread callStackSymbols]);
    [super layoutSubviews];

    [self reloadData];

}

//This method can be used to reload the entire control
-(void)reloadData{
//Reload the subviews of control
}
每当滚动滚动视图时,都会在iOS版本4.3中调用layoutSubviews方法。但在4.3(5.0,6.0)以上的版本中,不会调用此事件处理程序

在我的用例中,我不希望调用LayoutSubView


如何确保在滚动时有一个不会触发layoutsubviews方法的滚动视图?

我提出的解决方案如下:

  • 在自定义视图的顶部添加容器UIView(供参考ScrollViewHolder)
  • 然后在视图滚动视图保持架上添加UIScrollView
  • ----自定义UIView

    ----------------另一种观点

    -------------------------------UIScrollView

    -(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if(self){
    
    //Allocation and Initialization of ScrollView
    //...
    [super addSubView:scrollView];
    
    }
    return self;
    }
    
    - (void)layoutSubviews {
    
        DLog(@"%@",[NSThread callStackSymbols]);
        [super layoutSubviews];
    
        [self reloadData];
    
    }
    
    //This method can be used to reload the entire control
    -(void)reloadData{
    //Reload the subviews of control
    }
    
    --------------------------------------------ScrollView中的子视图

    -(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if(self){
    
    //Allocation and Initialization of ScrollView
    //...
    [super addSubView:scrollView];
    
    }
    return self;
    }
    
    - (void)layoutSubviews {
    
        DLog(@"%@",[NSThread callStackSymbols]);
        [super layoutSubviews];
    
        [self reloadData];
    
    }
    
    //This method can be used to reload the entire control
    -(void)reloadData{
    //Reload the subviews of control
    }
    
    init方法现在更改为以下内容:

    -(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if(self){
    
    //Allocation and Initialization of Container View
    
    [super addSubView:ScrollViewHolder];
    //Allocation and Initialization of ScrollView
    //...
    [ScrollViewHolder addSubView:scrollView];
    
    }
    return self;
    }