简体   繁体   中英

Recursion in - (void)layoutSubviews in iOS7 But works fine in iOS8

I am stuck in a strange issue. I have a view on which i have added autolayout. And inside that view there are few labels which are subclass of UILabel. Inside that subclass i override function - (void)layoutSubviews (the function itself is empty) Now the problem is that sometimes the - (void)layoutSubviews function called multiple times.

the stack trace of the same is as follows.

`#1 0x00824964 in -[UIView(CALayerDelegate) layoutSublayersOfLayer:] ()
 #2 0x01f4682b in -[NSObject performSelector:withObject:] ()
 #3 0x01c1045a in -[CALayer layoutSublayers] ()
 #4 0x01c04244 in CA::Layer::layout_if_needed(CA::Transaction*) ()
 #5 0x01c040b0 in CA::Layer::layout_and_display_if_needed(CA::Transaction*) ()
 #6 0x01b6a7fa in CA::Context::commit_transaction(CA::Transaction*) ()
 #7 0x01b6bb85 in CA::Transaction::commit() ()
 #8 0x01b6c258 in CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) ()
 #9 0x0296436e in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#10 0x029642bf in __CFRunLoopDoObservers ()
#11 0x02942254 in __CFRunLoopRun ()
#12 0x029419d3 in CFRunLoopRunSpecific ()
#13 0x029417eb in CFRunLoopRunInMode ()
#14 0x04b785ee in GSEventRunModal ()
#15 0x04b7842b in GSEventRun ()
#16 0x007b5f9b in UIApplicationMain () `

Now i am not able to understand from where it is getting called as stack trace is not showing anything. Can anyone help to track down the origin of the recursion here.

EDIT:- It seems like the issue with autolayouts. If i remove the autolayout from the view there is no more sublayout issue exists. Any suggestion why this is happening.

It seems like an issue with autolayout. Whenever i use the autolayout with aspect ratio on the view the problem appears. Remove the aspect ratio from the autolayout and the issue get solved for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM