When is UIView.didAddSubview called? - ios

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

Related

Swift - UIViews order programmatically

I have several UIView layers in one ViewController.
How can I determine the order of UIView programmatically?
I found the solution...
In the UIView documentation, where are several methods listed for the manipulation of the order of subviews:
bringSubviewToFront(_:)
sendSubviewToBack(_:)
removeFromSuperview()
insertSubview(_:atIndex:)
insertSubview(_:aboveSubview:)
insertSubview(_:belowSubview:)
exchangeSubviewAtIndex(_:withSubviewAtIndex:)
In Swift 4.0
view.sendSubview(toBack:yourUIView)
view.bringSubview(toFront:yourUIView)
Views are ordered from back-most to front-most in view.subviews array.
For example, here are 3 subview added to an empty view.
view.addSubview(UILabel())
view.addSubview(UIButton())
view.addSubview(UITextField())
Printing the subviews with the following code
for view in view.subviews {
print(view.debugDescription)
}
has the output
<UILabel: 0x7feef00042e0; frame = (0 0; 0 0); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60400008c210>>
<UIButton: 0x7feef00045c0; frame = (0 0; 0 0); opaque = NO; layer = <CALayer: 0x604000222300>>
<UITextField: 0x7feeef02c800; frame = (0 0; 0 0); text = ''; opaque = NO; gestureRecognizers = <NSArray: 0x60800005b090>; layer = <CALayer: 0x604000222280>>
When the views are reordered, the position in view.subviews changes
if let button = view.subviews.first(where: { $0 is UIButton }) {
view.bringSubview(toFront: button)
}
Now, printing the view, has the output
<UILabel: 0x7feef00042e0; frame = (0 0; 0 0); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60400008c210>>
<UITextField: 0x7feeef02c800; frame = (0 0; 0 0); text = ''; opaque = NO; gestureRecognizers = <NSArray: 0x60800005b090>; layer = <CALayer: 0x604000222280>>
<UIButton: 0x7feef00045c0; frame = (0 0; 0 0); opaque = NO; layer = <CALayer: 0x604000222300>>

UITouch is not working with ios8

I am working on one app. Which capture images continuously, there is one button to stop capturing. But the problem is that button targeted method is not being called. Even when I clicked on the screen anywhere it didn't detect touch or gesture. I have implemented gesture and touch delegate methods to check. Capturing image is not on main thread so main thread is free. So I am not able to find the reason why view not able to detect the touch. There are almost 6-7 button on that particular view, none of them trigger their method. While working with ios7 its running properly, It will detect touch and button targeted method trigger also.
I have thought that there should be any-view that will be overlap those button so i print the stake of subview , which is as below.Button which stop capturing is with text "START". I have just share stake after START button only as i think in stake the last item will be on top in view.
<UIButtonLabel: 0x15dfb0d0; frame = (5 14; 41 16); text = 'START';
opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer:
0x15dfb190>>
<UIButton: 0x15e8c590; frame = (63 7; 36 32); opaque = NO; autoresize
= RM+BM; layer = <CALayer: 0x15e8c690>>
<UIButtonLabel: 0x15df0400; frame = (15 10; 6 12); text = '0'; opaque
= NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x15d98db0>>
<UIImageView: 0x15e97c00; frame = (-295 -272; 1557 1568);
clipsToBounds = YES; hidden = YES; autoresize = W+H;
autoresizesSubviews = NO; layer = <CALayer: 0x15ea2920>>
<_UILayoutGuide: 0x15e90ba0; frame = (0 0; 0 0); hidden = YES; layer =
<CALayer: 0x15ea2b10>>
<_UILayoutGuide: 0x15e86120; frame = (0 1024; 0 0); hidden = YES;
layer = <CALayer: 0x15e6fc40>>
<MPVolumeView: 0x15db7840; frame = (18 340; 284 23); alpha = 0; opaque
= NO; layer = <CALayer: 0x15dbd2e0>>
<UILabel: 0x15daee40; frame = (0 0; 0 0); text = 'No Volume
Available'; opaque = NO; autoresize = W+BM; userInteractionEnabled =
NO; layer = <_UILabelLayer: 0x15dd5be0>>
<MPButton: 0x15dd5e00; baseClass = UIButton; frame = (131.5 2.5; 21.5
18); alpha = 0; opaque = NO; autoresize = LM+BM; layer = <CALayer:
0x15dd6030>>
<UIImageView: 0x15de0c30; frame = (-39.25 -41; 100 100); alpha = 0;
opaque = NO; userInteractionEnabled = NO; tag = 1886548836; layer =
<CALayer: 0x15ea5330>>
<UIImageView: 0x15ea5790; frame = (0 0; 21.5 18); clipsToBounds = YES;
opaque = NO; userInteractionEnabled = NO; layer = <CALayer:
0x15ea5810>>
I am using auto-layout. Please can you help me to handle this problem. I am new with auto-layout. so anything that i can change in storyboard get this problem solved please let me know. Thanks in advance.
Thanks for all your answers. I got solution by moving irate code from +initialize method of AppDelegate to didFinishLaunchingWithOptions method. My iRate get initialized and configure but don't show popup. May be that's why i was not able to perform any touch on screen.

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.

Issue with constraints on bottom layout

I'm getting some issues with a constraint relative from the bottom layout.
There are some views inside a UITabBarViewController. When I change to another view from the tab and return to first one, the viewcontroller not recognize the bottom layout as the tab bar, but from the bottom of the view.
I uploaded the problem here: https://sites.google.com/site/rveducationapps/layoutError.png?attredirects=0&d=1
I already tried put in ViewDidAppear and also ViewWillAppear:
[self.view layoutSubviews];
[self.view setNeedsUpdateConstraints];
I logged the subviews in the two cases, the right one and after I exit and return to the view:
subviews:(
"<UIView: 0x146b2260; frame = (210 0; 814 712); autoresize = RM+BM; layer = <CALayer: 0x146b22c0>>",
"<UIButton: 0x146a9eb0; frame = (727 672; 287 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x146aa070>>",
"<UITableView: 0x151d3400; frame = (0 0; 210 761); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x146b14b0>; layer = <CALayer: 0x146ade20>; contentOffset: {0, 0}>",
"<_UILayoutGuide: 0x146b23b0; frame = (0 0; 0 20); hidden = YES; layer = <CALayer: 0x146b24a0>>",
"<_UILayoutGuide: 0x146b28a0; frame = (0 712; 0 56); hidden = YES; layer = <CALayer: 0x146b2910>>"
)
subviews:(
"<UIView: 0x146b2260; frame = (210 0; 814 768); autoresize = RM+BM; layer = <CALayer: 0x146b22c0>>",
"<UIButton: 0x146a9eb0; frame = (727 728; 287 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x146aa070>>",
"<UITableView: 0x151d3400; frame = (0 0; 210 817); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x146b14b0>; layer = <CALayer: 0x146ade20>; contentOffset: {0, 0}>",
"<_UILayoutGuide: 0x146b23b0; frame = (0 0; 0 20); hidden = YES; layer = <CALayer: 0x146b24a0>>",
"<_UILayoutGuide: 0x146b28a0; frame = (0 768; 0 0); hidden = YES; layer = <CALayer: 0x146b2910>>"
)
I see there are some differences, specially in:"<_UILayoutGuide: 0x146b28a0; frame = (0 712; 0 56); hidden = YES; layer = <CALayer: 0x146b2910>>"
But I don't know how to fix it.
EDITED:
I think I fixed. I selected the UIViewController in the Storyboard and disabled the EXTEND EDGES->Under Bottom Bars option.
If you are transitioning from your UITabBarViewController to a new UIViewController, and then attempting to go back to your tabBarController from that UIViewController, then you could simply segue back to the UITabBarViewController(The segue will take you back to your rootViewController for your UITabBarViewController).
If you need to transition back to a specific tab, instantiate a custom segue and send it back to a different tab using a different specified VC, this can be set in your UITabBarViewController class or in your applications AppDelegate.m file.

How does view layering affect a views positioning?

This question has been re-written, since I think it has more to do with views and layers than the original 'Finding the center of a tableview'. Also in hope of finding another answer.
In question, is a set of 4 views to show activity, in a tableview, in a tab bar.
The code of:
NSLog(#"view.center: %#", self.view.center);
NSLog(#"view.frame: %#", self.view.frame);
Produces, on first display of 'loading':
view.center: {160, 250}
view.frame: {{0, 20}, {320, 460}}
For 2nd (and subsequent) displays: (after a pop up date picker)
view.center: {160, 205.5}
view.frame: {{0, 0}, {320, 411}}
Self (ListViewController) is subclass of UITableViewController. So, the height of the view (or tableview) frame is changing. Why?
I've been exploring and found this info in the debugger, that seems relevant.
--- Before ---
[self parentViewController]:
<UITabBarController: 0x6e115a0>
[[self parentViewController] view]:
<UILayoutContainerView: 0x6e1b750; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x6e0c8f0>>
self: <ListsViewController: 0x6e13730>
[self tableView]:
<UITableView: 0x71e4000; frame = (0 20; 320 460); clipsToBounds = YES; opaque = NO; autoresize = W+H; layer = <CALayer: 0x6834db0>; contentOffset: {0, 0}>
[[self view] subviews]: (array)
<UIImageView: 0x6825e30; frame = (0 453; 320 7); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x6835a90>>,
<UIImageView: 0x68314e0; frame = (313 411; 7 20); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x683d120>>,
<UIView: 0x6a054f0; frame = (0 0; 320 460); alpha = 0.4; tag = 12; layer = <CALayer: 0x6a07840>>,
<UIView: 0x6a04c60; frame = (110 155.5; 100 100); alpha = 0.6; tag = 13; layer = <CALayer: 0x6a073c0>>,
<UILabel: 0x6a07480; frame = (110 200.5; 100 50); text = 'Loading ...'; clipsToBounds = YES; userInteractionEnabled = NO; tag = 14; layer = <CALayer: 0x6a065b0>>,
<UIActivityIndicatorView: 0x6a07a80; frame = (140 167.5; 40 40); tag = 15; layer = <CALayer: 0x6a07b40>>
--- After datepicker ---
[self parentViewController]:
<UITabBarController: 0x6e115a0>
[self parentViewController] view]:
<UILayoutContainerView: 0x6e1b750; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x6e0c8f0>>
self: <ListsViewController: 0x6e13730>
[self tableView]:
<UITableView: 0x71e4000; frame = (0 0; 320 411); clipsToBounds = YES; opaque = NO; autoresize = W+H; layer = <CALayer: 0x6834db0>; contentOffset: {0, 0}>
[[self view] subviews]:
<DetailTableViewCell: 0xb642120; baseClass = UITableViewCell; frame = (0 369; 320 44); autoresize = W; layer = <CALayer: 0xb642230>>,
<DetailTableViewCell: 0xb643850; baseClass = UITableViewCell; frame = (0 325; 320 44); autoresize = W; layer = <CALayer: 0xb643960>>,
<DetailTableViewCell: 0xb6435c0; baseClass = UITableViewCell; frame = (0 281; 320 44); autoresize = W; layer = <CALayer: 0xb6436d0>>,
<DetailTableViewCell: 0xb63cf30; baseClass = UITableViewCell; frame = (0 237; 320 44); autoresize = W; layer = <CALayer: 0xb63d130>>,
<DetailTableViewCell: 0x6a14050; baseClass = UITableViewCell; frame = (0 193; 320 44); autoresize = W; layer = <CALayer: 0x6a16fb0>>,
<DetailTableViewCell: 0x6a13760; baseClass = UITableViewCell; frame = (0 149; 320 44); autoresize = W; layer = <CALayer: 0x6a13870>>,
<DetailTableViewCell: 0x6a10920; baseClass = UITableViewCell; frame = (0 105; 320 44); autoresize = W; layer = <CALayer: 0x6a10010>>,
<DetailTableViewCell: 0xb63ce20; baseClass = UITableViewCell; frame = (0 60; 320 45); autoresize = W; layer = <CALayer: 0xb63c3e0>>,
<UIImageView: 0x6825e30; frame = (0 404; 320 7); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x6835a90>>,
<UIView: 0xb6477f0; frame = (0 0; 320 60); autoresize = W; layer = <CALayer: 0xb647820>>,
<UIImageView: 0x68314e0; frame = (313 411; 7 20); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x683d120>>,
<UIView: 0x6a098a0; frame = (0 0; 320 411); alpha = 0; tag = 9; animations = { opacity <CABasicAnimation: 0xb6279f0>; }; layer = <CALayer: 0x6a154b0>>,
<UIDatePicker: 0x6a23350; frame = (0 455; 320 216); tag = 10; animations = { position <CABasicAnimation: 0xb63bd40>; }; layer = <CALayer: 0x6a20590>>,
<UIToolbar: 0x6843f60; frame = (0 411; 320 44); opaque = NO; tag = 11; animations = { position=<CABasicAnimation: 0xb645f80>; }; layer = <CALayer: 0x6844a20>>,
<UIView: 0xb60baa0; frame = (0 0; 320 411); alpha = 0.4; tag = 12; layer = <CALayer: 0xb626af0>>,
<UIView: 0xb626b20; frame = (110 155.5; 100 100); alpha = 0.6; tag = 13; layer = <CALayer: 0xb626930>>,
<UILabel: 0xb60cfb0; frame = (110 200.5; 100 50); text = 'Loading ...'; clipsToBounds = YES; userInteractionEnabled = NO; tag = 14; layer = <CALayer: 0xb60d020>>,
<UIActivityIndicatorView: 0xb649e20; frame = (140 167.5; 40 40); tag = 15; layer = <CALayer: 0xb626960>>
You can use tableview.frame to access the origin points and it's dimensions. You can use tablview.center which is a CGPoint which gives you the center point of the object.

Resources