0

我已经自定义 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 方法的滚动视图?

4

1 回答 1

0

我想出的解决方案如下:

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

----自定义UIView

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

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

-------------------------------------------------------- ScrollView 中的子视图

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;
}
于 2012-11-30T10:02:53.220 回答