ios - UIScrollView Frame Always CGRectZero -
i have nib has standard uiview , i've included uiscrollview iboutlet (yes, hooked up), not subview of main uiview, out on own. autolayout turned off. scroll view has several subviews , larger main view. in viewwillappear:, set content size of uiscrollview current frame size, , set frame size of main view, , add together subview of main view.
unfortunately, nil showing up. when nslog frame of uiscrollview, coming {0, 0, 0, 0} (cgrectzero). thought odd, went , tried logging frame before changes it. still zeroes. logged out in viewdidload before done of view elements. still zeroes. (fwiw in nib, frame {0, 0, 320, 896})
i've had issue several of controllers, seems nail or miss. works, other times empty frame. typically, recreating scratch seems prepare issue, don't know why, i'm setting same both times.
running xcode version 6.1 (6a1052d), ios sdk 8.1 deployment target of 7.0
let me know if there other relevant info can give might help.
edit 1: address questions uiscrollview beingness "subview", here view heirarchy looks in document outline: can see, uiscrollview "subview" of view controller, not subview of "main" uiview has controller's view outlet.
edit 2: more images , code. here improve @ how nib set up:
i add together scrollview main uiview follows:
- (void)viewwillappear:(bool)animated { [super viewwillappear:animated]; scrollview.contentsize = scrollview.frame.size; scrollview setframe:cgrectmake(0, 100, self.view.frame.size.width, self.view.frame.size.height - 100); // modified because there other variables determine y position , height [self.view addsubview:scrollview] } but still don't think of code matters- whatever reason, uiscrollview coming nil. if have view created in nib, outlet connected properly, how view still nil? i'm creating controller via initwithnibname i've tried cleaning project, , removing app , reinstalling.
best guess on answer, , comments:
nibs serialised object trees. can have many view want root. problem (big one!) if not "connected" outletsretain them, @ point loose references. since uiscrollview not subview of main view controller view on nib, it's not retained (views retain subviews). so, it's retain on view controller.
my guess @ point trying set frame in view controller, scroll view gone. i'm not sure how sure when doing it, might after run loops, unretained scroll view dealloced.
workarounds: instead of variableiboutlet, utilize strong property (@property (strong, nonatomic) iboutlet uiscrollview *scrollview). add __strong qualifier variable. add uiscrollview subview within nib, when object tree deserialised it's retained parent. given purposefully set uiscrollview outside of main view hierarchy, i'm assuming don't want alternative 3, i'll go 1.
ios objective-c xcode uiscrollview
No comments:
Post a Comment