【问题标题】:Why UIScrollView's scrolling triggers layoutSubViews method in iOS 4.3 but not in 5.0 & above?为什么 UIScrollView 的滚动会在 iOS 4.3 中触发 layoutSubViews 方法,而在 5.0 及以上版本中却没有?
【发布时间】:2012-11-30 09:56:16
【问题描述】:

我已经自定义 UIView 来创建自定义 UI 组件。

视图的层次结构是这样的。

----自定义UIView

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

------------------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
}

当滚动视图被滚动时,layoutSubviews 方法在 iOS 4.3 版本中被调用。但在 4.3 (5.0 , 6.0) 以上版本的情况下,不会调用此事件处理程序。

在我的用例中,我不希望 layoutsubviews 被调用。

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

【问题讨论】:

    标签: ios5 uiscrollview ios4 layoutsubviews


    【解决方案1】:

    我想出的解决方案如下:

    1. 在自定义视图之上添加一个容器 UIView(供参考 ScrollViewHolder)
    2. 然后在视图ScrollViewHolder上添加UIScrollView。

    ----自定义UIView

    ----------------另一个 UIView

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

    --------------------------------------------子视图在滚动视图

    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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-19
      • 1970-01-01
      • 1970-01-01
      • 2011-05-04
      • 2011-02-18
      • 1970-01-01
      相关资源
      最近更新 更多