iOS - UIView description frame doesn't match debugger recursiveDescription frame - ios

I came across this while debugging why my scrollView wouldn't scroll. For context, the structure of my layout is:
-ScrollView
- View
- labels, images, buttons
Updating the scrollView.contentSize to match the (sub)view wasn't working, so I put in some debug statements. Turns out the view's frame is sized 0, 0 when i NSLog its description, but if i run the debugger's recursiveDescription, it shows different.
Any idea why, and could that be affecting why my scrolling isn't working?
From NSLog(#"%#", [self.view description])
2012-11-15 17:16:46.707 Comparo[65731:11303] starting: <UIView:
0x7144590; frame = (0 0; 0 0); autoresize = TM+BM; layer =
<CALayer: 0x714b4f0>>
2012-11-15 17:16:46.708 Comparo[65731:11303] 1: <UIView: 0x7144590;
frame = (0 0; 0 0); autoresize = TM+BM; layer = <CALayer:
0x714b4f0>>
2012-11-15 17:16:46.771 Comparo[65731:11303] 2: <UIView: 0x7144590;
frame = (0 0; 0 0); autoresize = TM+BM; layer = <CALayer:
0x714b4f0>>
2012-11-15 17:16:46.771 Comparo[65731:11303] 3: <UIView: 0x7144590;
frame = (0 0; 0 0); autoresize = TM+BM; layer = <CALayer:
0x714b4f0>>
2012-11-15 17:16:46.772 Comparo[65731:11303] 4: <UIView: 0x7144590;
frame = (0 0; 0 0); autoresize = TM+BM; layer = <CALayer:
0x714b4f0>>
Debugger output for: (lldb) po [[UIApp keyWindow] recursiveDescription]
...
| | | | <UIScrollView: 0x71494d0; frame = (0 0; 320 504);
clipsToBounds = YES; autoresize = TM+BM; gestureRecognizers =
<NSArray: 0x75d3bb0>; layer = <CALayer: 0x71f9ed0>;
contentOffset: {0, 0}>
| | | | | <UIView: 0x7144590; frame = (0 0; 320 523);
autoresize = TM+BM; layer = <CALayer: 0x714b4f0>>
Thanks.

Thanks Rob!
You were right about it being a timing issue and there's no way to guarantee that frames will be finalized in viewDidLoad (where I had my NSLog statements). I moved the statements to viewDidAppear:, which is where the user will first be able to interact with them and scroll anyway, and the numbers match up now.
Bonus: solved my scrolling issue too.

Related

iOS weird spacing before the first UITableVIewCell

There are tons of questions in the area but I can't seem to get it working.
I have a UITableView with autolayout 0 distance to superview from all edges.
ViewController has under opaque bars on (my NavigationBar is opaque)
AdjustScrollView inset is ON (and gets a nice contentOffset: {0, -64};)
The first cell has a weird spacing of additional 35 px:
po [self.view recursiveDescription]
<UIView: 0x7fc8a28159c0; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x7fc8a2816d80>>
| <UITableView: 0x7fc8a1a4d000; frame = (0 0; 320 568); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fc8a2a3ea90>; layer = <CALayer: 0x7fc8a2a23450>; contentOffset: {0, -64}; contentSize: {320, 1429}>
| | <UITableViewWrapperView: 0x7fc8a2a01670; frame = (0 0; 320 568); gestureRecognizers = <NSArray: 0x7fc8a2810d80>; layer = <CALayer: 0x7fc8a2a25590>; contentOffset: {0, 0}; contentSize: {320, 568}>
| | | <MomentHeaderTableViewCell: 0x7fc8a2ad1630; baseClass = UITableViewCell; frame = (0 35; 320 504); autoresize = W; layer = <CALayer: 0x7fc8a2a02110>>
Where is it coming from?
What did the trick was:
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];
Found here:
Why is there extra padding at the top of my UITableView with style UITableViewStyleGrouped in iOS7

When is UIView.didAddSubview called?

When is UIView.didAddSubview called ?
I have created a simple View and ViewController app.
When I run this app, didAddSubview is called twice on first time the View appears.
https://github.com/toshi0383/HelloUIView
below is the log output
didAddSubView
<_UILayoutGuide: 0x7f92d3425210; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7f92d3419cf0>>
didAddSubView
<_UILayoutGuide: 0x7f92d3425c10; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7f92d34244a0>>
viewDidLoad
[<_UILayoutGuide: 0x7f92d3425210; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7f92d3419cf0>>, <_UILayoutGuide: 0x7f92d3425c10; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7f92d34244a0>>]
didMoveToWindow
didMoveToSuperView
layoutSubviews
<ViewTest.View: 0x7f92d3424bc0; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7f92d3423320>>
UILayoutGuide is a private Apple class.
UILayoutGuide is normally referred to -topLayoutGuide and -bottonLayoutGuide, those are not really constraints.
same questions here:
stack overflow : what-is-uilayoutguide

NSLayoutConstraints issue

I've disabled autolayout from xib. But I'm facing this issue. Even I'm not adding any subview programmatically, and I'm having 3 element in this view:
1. UIImageView 2. UIButton 3. UIButton.
I'm suffering for the last 3 days but I'm not able to find out the error. So please any one help me. Your help will be appreciated.
NSLog(#"Constratins %#",[self.view constraints]);
Constratins (
)
View hierarchy unprepared for constraint.
Constraint: <NSAutoresizingMaskLayoutConstraint:0x294d9de0 h=-&- v=-&- UIViewControllerWrapperView:0x2d91c410.midY == UINavigationTransitionView:0xdd2aa40.midY>
Container hierarchy:
<UINavigationTransitionView: 0xdd2aa40; frame = (0 0; 1024 768); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0xdd2aca0>>
| <UIViewControllerWrapperView: 0x2a72b4d0; frame = (0 0; 1024 768); layer = <CALayer: 0x2a72ab40>>
| | <UIView: 0x2d869b30; frame = (0 0; 1024 768); gestureRecognizers = <NSArray: 0x2d8852e0>; layer = <CALayer: 0x2d86b510>>
| | | <MyImageView: 0x2d891040; baseClass = UIImageView; frame = (0 0; 1024 748); userInteractionEnabled = NO; layer = <CALayer: 0x2d8699f0>> - (null)
| | | <UIButton: 0x2d88c460; frame = (968 14; 40 40); hidden = YES; opaque = NO; layer = <CALayer: 0x2d88c550>>
| | | <UIButton: 0x2d88a220; frame = (963 9; 40 44); opaque = NO; layer = <CALayer: 0x2d88a310>>
View not found in container hierarchy: <UIViewControllerWrapperView: 0x2d91c410; frame = (0 0; 1024 768); autoresize = W+H; layer = <CALayer: 0x2d91c490>>
That view's superview: NO SUPERVIEW
Yes, I found the solution. The reason is : not setting the frame of UIViewControllerWrapperView
So i've do this
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.tabBarController.view.superview.frame = self.view.bounds;
}

Mysterious _UIParallaxDimmingView. What is it?

I put a regular UITableView owned by a UITableViewController under UINavigationController.
Now, look at this code:
[BGHPTools vDoForeGroundAndWait:^{
PO(vi);
PO([vi superview]);
PO ([[vi superview]superview]);
PO ([[[vi superview]superview]superview]);
}];
NSArray * arObjects =blarGetArrayTobeParsedWith(weakBODo);//No view object is manipulated here!!!!
[BGHPTools vDoForeGroundAndWait:^{
PO(vi);
PO([vi superview]);
PO ([[vi superview]superview]);
PO ([[[vi superview]superview]superview]);
}];
The code blarGetArrayTobeParsedWith simply download stuff from internet and for all display purpose, just do nothing and wait for a while
The first set of PO is like this:
2013-12-10 21:14:43.257 [8620:9407] vi: <BGTableViewWithBackgroundAndTopAndBottom: 0xd36d600; baseClass = UITableView; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x15d64320>; layer = <CALayer: 0x15d64890>; contentOffset: {0, -64}>
2013-12-10 21:14:43.259 [8620:9407] [vi superview]: <_UIParallaxDimmingView: 0x15f48a40; frame = (0 0; 320 480); opaque = NO; layer = <CALayer: 0x15f79d00>>
2013-12-10 21:14:43.259 [8620:9407] [[vi superview]superview]: <UIView: 0x15850530; frame = (0 0; 320 480); layer = <: 0x15860480>>
2013-12-10 21:14:43.261 [8620:9407] [[[vi superview]superview]superview]: <UIViewControllerWrapperView: 0xcb35660; frame = (0 0; 320 480); autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0xcb392f0>>
The second set of PO shows
2013-12-10 21:22:26.145 [8620:9407] vi: <BGTableViewWithBackgroundAndTopAndBottom: 0xd36d600; baseClass = UITableView; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x15d64320>; layer = <CALayer: 0x15d64890>; contentOffset: {0, -64}>
2013-12-10 21:22:26.145 [8620:9407] [vi superview]: <UIViewControllerWrapperView: 0xcb35660; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0xcb392f0>>
2013-12-10 21:22:26.146 [8620:9407] [[vi superview]superview]: <UINavigationTransitionView: 0x11cac940; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x11cad190>>
2013-12-10 21:22:26.146 [8620:9407] [[[vi superview]superview]superview]: <UILayoutContainerView: 0x11ca8ef0; frame = (0 0; 320 480); autoresize = W+H; gestureRecognizers = <NSArray: 0x11cb1070>; layer = <CALayer: 0x11ca69e0>>
It seems that vi, which is a UITableView, then changes its parent view.
Why?
_UIParalaxDimmingView, judging from the name, has two purposes:
Dim content behind the wrapped controller
Add a paralax effect to the wrapped controller
I am not sure about your view hierachy but I would expect this kind of controller in the following situations:
Presented view controller
UIPopoverController
During specific controller transitions (animations)
If blarGetArrayTobeParsedWith downloads data from the internet, the difference could be between view hierarchy when animation is running and when animation has ended.

What is the iPhone's "Springboard" view exactly?

My question is, is the default iPhone menu a UIcollection view created with storyboarding, or is there more to its abilities? (in order to avoid emulating its functionality)
If you want to understand SpringBoard's view hierarchy:
Launch the iOS Simulator if it's not already running.
Make sure you're looking at SpringBoard in the simulator.
In Xcode, choose Product > Attach to Process > springboard. The springboard process is way down in the “System” section of the list.
Still in Xcode, choose Product > Debug > Pause.
In Xcode's debug console (where it should show the (lldb) prompt), type po [[UIApp keyWindow] recursiveDescription].
Voila, you get a printout of SpringBoard's entire on-screen view hierarchy. Mine starts out like this:
(lldb) po [[UIApp keyWindow] recursiveDescription]
$0 = 0x0b63abf0 <SBAppWindow: 0xce3ef10; baseClass = UIWindow; frame = (0 0; 320 480); layer = <UIWindowLayer: 0xce3f010>>
| <SBUIRootView: 0xb162de0; frame = (0 0; 320 480); layer = <CALayer: 0xb162e60>>
| | <UIView: 0xb163010; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0xb1630c0>>
| | | <SBWallpaperView: 0xb1632a0; baseClass = UIImageView; frame = (0 0; 320 480); userInteractionEnabled = NO; layer = <CALayer: 0xb160f70>>
| | | | <UIImageView: 0xb1610d0; frame = (0 0; 0 0); hidden = YES; userInteractionEnabled = NO; layer = <CALayer: 0xb161130>>
| | | | <UIImageView: 0xb161160; frame = (0 0; 0 0); hidden = YES; userInteractionEnabled = NO; layer = <CALayer: 0xb163390>>
| | | <SBIconContentView: 0xb163da0; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0xb163e50>>
| | | | <UIView: 0xc939710; frame = (0 371; 320 109); opaque = NO; autoresize = W+TM; layer = <CALayer: 0xc939770>>
| | | | | <SBDockIconListView: 0xc9381d0; frame = (0 20; 320 89); autoresize = TM; layer = <CALayer: 0xc9382c0>>
...
From Wikipedia article on Springboard:
Springboard, or Home Screen is the standard application that manages the iOS home screen. Other tasks include starting WindowServer, launching and bootstrapping applications and setting some of the device's settings on startup.

Resources