Who moved my view? - iphone

Using storyboard ,I created a project.
Inside viewDidLoad,I did :
NSLog(#"%#",self.view.description);
I got :
<UIView: 0x8789cb0; frame = (0 20; 320 460); autoresize = RM+BM; layer = <CALayer: 0x8789d50>>
But inside another XXControllerDelegate Method , I got :
<UIView: 0x8789cb0; frame = (0 0; 320 416); autoresize = RM+BM; layer = <CALayer: 0x8789d50>>
I found the fact if I didn't choose Resize View From NIB
I always got :
frame = (0 0; 320 416)
But I couldn't find anywhere resize the view from NIB.Who moved my view ?

Your view has RM+BM these anchors will be able to move the view y and x position in regarding to the parent view, when viewDidLoad is called the superview gets its size from the xib file, when viewWillAppear is getting called, the view will resize to the superview
If you want your view to not resize you should remove the RM+BM, check the screen shot
Remove the red horizontal and vertical lines in the right middle part of the image bellow

The frame of an UIView are relative to the superview it is contained within.
The bounds of an UIView are relative to its own coordinate system.
So you need to be sure where you are adding your view.

Related

How to prevent keyboard from resizing Collection Views swift 3

As the title says, whenever i click on the search bar or any textfield really the keyboard appears and resizes the view. I have a collection view inside another collection view so i wouldnt mind if the collection view that resizes is the one inside, but its resizing the outside collection view. I have tried almost everything I can think of. So if anyone have any suggestion, I will greatly appreciated.
I already tried with supplementary views, uisearchcontroller... I dont know what else to do.. is like this has a listener that resizes the bottom constraint. This is the error method im getting, a bunch of times ( like 20 times everytime the keybarod appears)
the behavior of the UICollectionViewFlowLayout is not defined because:
2016-09-27 22:27:04.726 APP[1446:734553] the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
2016-09-27 22:27:04.727 APP[1446:734553] The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x14c6efa60>, and it is attached to <UICollectionView: 0x14d03d600; frame = (0 50; 414 622); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x14c5a2a80>; layer = <CALayer: 0x14c5bdf40>; contentOffset: {414, 0}; contentSize: {1242, 622}> collection view layout: <UICollectionViewFlowLayout: 0x14c6efa60>.
2016-09-27 22:27:04.727 APP[1446:734553] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.

View isn't rotating properly

I have this code inside a UIViewController subclass:
- (id)init {
self = [super init];
if (self) {
self.view.frame = [PDToolbox screenFrame];
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.view.backgroundColor = [UIColor redColor];
}
return self;
}
The only thing I have in terms of any rotation methods is this:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return YES;
}
Yet after the screen is rotated to landscape, doing an NSLog on the view shows this:
<UIView: 0x10061640; frame = (0 0; 320 480); transform = [0, -1, 1, 0, 0, 0]; autoresize = W+H; layer = <CALayer: 0x10061670>>
I don't understand why it's doing this transform thing, and not just rotating like normal? It means any views i place on top of it after the rotation and set to be the size of the view end up at a 320x480 position.
EDIT:
People aren't understanding. So I put a view on top of it, the same size as the UIView, using:
UIView *anotherView = [UIView alloc] initWithFrame:controller.view.bounds];
[controller.view addSubview:anotherView];
If I add anotherView in in portrait, anotherView appears in portrait, with the frame 320x480.
If i add anotherView in in landscape, anotherView appears in landscape, but still with the frame 320x480, becaus that's what the controller.view's frame is still, for some unknown reason.
What does your view/controller hierarchy look like? It looks to me like something is setting a 90° rotation transformation on your view, rather than changing the view's frame. If you're not doing that yourself, it's likely a parent view or view controller.
Frame and bounds are very different things. You should read Apple's guide to View Geometry - it contains a lot of information that's been invaluable to me.
Your bounds is always going to be 320x480 because someone is setting your transform (which affects the frame, but not the bounds).
Make sure your view controller's view's superview has autoresizesSubviews set to YES and that any subviews added have appropriate autoresizingMasks.

UIScrollView initializing with two uiimageviews from system?

I have a Nib with a scrollview which i use on my controller. I have to make some constant calculations based on the scrollview.subviews count. However, surprisingly the scrollview is always starting with two uiimage views.
The scrollview at my Nib file is empty, and i have even checked the nib source code to assure there is no garbage there. I also deleted the scrollview and created another with the same result.
I am always receiving the same views there (always at, so my scrollview.subviews.count always start at 2. What could be causing this??
If I print scrollview subviews just after initializing view..
[[NSBundle mainBundle] loadNibNamed:#"TileScreen" owner:self options:nil];
NSLog(#"Started scrollview with subviews %#", _scrollView.subviews);
I receive:
Started scrollview with subviews (
"<UIImageView: 0x1dcb50; frame = (294 400; 7 7); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x1e51b0>>",
"<UIImageView: 0x1bb6a0; frame = (294 400; 7 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x1a9b50>>"
)
Well before I posted this question I understood the problem. I wanted to share in case someone falls into this.
The problem is that the "Show horizontal scrollbar, Show vertical scrollbar" add the mentioned UIImageViews. You can avoid this by simply unchecking the property on the IB.
If you want to show the scrollbars though, you will need to take into account these two views in your count.

UIScrollView contentSize Issue - With example code

Within my view I create a scrollview with a width of 320 and a height of 70.
Responding to the user touching a button, I expand the scrollview, so it is 380(h) x 320(w) in size.
The code for this is shown below:
CGRect scrollviewFrame = CGRectMake(0, 30, 320, 380);
[scrollView setFrame:scrollviewFrame];
[self layoutScrollImages:YES];
CGSize srect = CGSizeMake([scrollView bounds].size.width, (kNumImages * (kScrollObjHeight + 10)));
[scrollView setContentSize:srect];
The constants mentioned in the above snippet are defined as:
const CGFloat kScrollObjHeight = 80;
const NSUInteger kNumImages = 100;
As I debug this project, I can see that srect is 320 (w) x 8000 (h) in size; however my issue is the scrollable area (where the user can actually touch to scroll the scrollview) remains the same as when it was it's original size.
I'm obviously missing something, does anyone know what it is?
have created a sample project to illustrate the issue I am having, it is available here: http://dl.dropbox.com/u/9930498/ScrollViewTest.zip
The problem in your sample is you have a very odd structure for loading your views. As such the view you're adding to the DetailScrollView instance is the root view of the DetailScrollView.xib, not the scrollview itself, which I believe is what you were expecting.
Fastest way to fix your problem is to adjust the root view in DetailScrollView.xib to autoresize width and height.
A UIView cannot respond to touches that are outside of the bounds of its superview. In your example, it appears that you expand the scroll view, but the scroll view's parent is still only 100 units high.
You should imagine the scrollView as a window, where by the window I mean the frame of the scrollView, which is also the coordinates that the scrollView detects your touches. By setting the contentView as 320 (w) x 8000 (h) you only change the content of the scroll view, which is the complete area behind that window.
By expanding content view, the scrollView can scroll a broader area, but in order to detect touches in a bigger rect, you should change frame of the scroll view.

How In-Call status bar impacts UIViewController's view size?

I'm trying to understand how the view associated to a UITabBarController, UINavigationController or UIViewController reacts when the in-call status bar is toggled.
My trouble is that they seem to behave differently and this causes me side effects.
I've made a project that changes the root view controller of the window for the 3 types above and I dump the description of the view to get the frame coordinates.
UIViewController
inCall status OFF:
UIView: 0x4e2a1f0; frame = (0 20; 320 460); autoresize = W+H; ....
ON
UIView: 0x4e2a1f0; frame = (0 40; 320 440); autoresize = W+H; ...
This one I understand : when the in-call status bar appears, the height of the view of the UIViewController shrinks and looses 20, and its y coord moves from 20 to 40.
That's perfect ! I would expect the same when replacing a classic UIViewController with a UITabBarController or a UINavigationController but that's not the case !
UINavigationController
InCall status bar OFF
UILayoutContainerView: 0x4b35ab0; frame = (0 0; 320 480); autoresize = W+H; ..
ON
UILayoutContainerView: 0x4e1b060; frame = (0 0; 320 480); autoresize = W+H; ..
In that case, the view handled by the UINavigationController does not have its frame properties changed when the in-call status bar is toggled?! (why ? :( )
UITabBarController
OFF
UIView: 0x4b2f6a0; frame = (0 20; 320 460); autoresize = W+H; ...
ON
UIView: 0x4b2f6a0; frame = (0 20; 320 460); autoresize = W+H; ...
Same as in the UINavigationController: the view of the UITabBarController does not seem to be impacted when the incall status bar is toggled.
Can someone explain me how this resize works when displaying the incall status bar appears ?
My end goal is to display a UIView that is shown ABOVE the whole UITabBarController and that resizes properly when the in call status is displayed. However, I really don't know where to put such a view in the views hierarchy : if I add it as a child of the UITabBarController's view, as this one does not react to the incall status display, mine does not react as well :(
The height of the view when the In-call status bar is toggled depends on the way it's anchored.
Play around with the autoResizingMask of the UIView to control whether the view should move down or resize when the in-call status bar shows up.
These two properties,
UIViewAutoresizingFlexibleTopMargin
UIViewAutoresizingFlexibleHeight
will help you. The first one pushes the view down, the second one changes the size.
Your regular UIViewController example has [wantsFullScreenLayout] set to NO, which causes the view to be automatically sized so it doesn't go under the status bar.
UINavigationController and UITabBarController, on the other hand, default wantsFullScreenLayout to YES. So their views take up the whole window, and they size and position their subviews themselves to appropriately handle the status bar. If you explicitly set the property on these controllers to NO, you should get the behavior you desire (but will then lose the ability to properly handle child controllers that set wantsFullScreenLayout to YES, if you care about that).
In your UITabBarController example, BTW, it seems that you are not printing the information for the view of the tab bar controller; here that is a UILayoutContainerView, not a plain UIView.
Ideally you should forget about how much amount the view gets resized and play around with Autoresizing mask.