I have customized UIView to create a custom UI component.

The hierarchy of views are this way.

----Custom UIView

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

-----------------------------Sub Views in 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
}

When ever the scroll view is scrolled, the layoutSubviews method gets called in iOS version 4.3. But in case of versions above 4.3 (5.0 , 6.0) this event handler does not get called.

In my use case, I do not wanted the layoutsubviews to get called.

How can I ensure that I have a scroll view when scrolled that does not trigger the layoutsubviews method?

有帮助吗?

解决方案

The solution I came up with is below:

  1. Add a container UIView (for reference ScrollViewHolder)on top of the customized view
  2. Then add the UIScrollView on the view ScrollViewHolder.

----Custom UIView

----------------Another UIView

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

--------------------------------------------Sub Views in ScrollView

The init method is now changed to the following:

-(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;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top