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.
Related
I have a scrollView embedded inside a UIView with a top constraint to the navigation bar.
My question is, how is the page size calculated of a UIScrollView (where scrollView.pagingEnabled = true)? I want each page to be the size of the aforementioned UIView, but it turns out that it's slightly bigger.
I set the contentSize as so in the view controller:
self.scrollView.contentSize = CGSizeMake(UIScreen.mainScreen().bounds.width, (UIScreen.mainScreen().bounds.height - 64) * 4)
I figured each page size would be UIScreen.mainScreen().bounds.height - 64 (because of the navigation bar and clock) but, like I said, the page turns out to be slightly bigger.
Try to set the height of the scrollView same as UIView that hosts it self.scrollView.superview.
Edit:
The 'slightly bigger' is probably the 64 points offset. You need to set self.automaticallyAdjustsScrollViewInsets = false inside yout viewController that hosts the scrollView to fix it
I have a scrollview inside which i have 20 UItextviews. The scrollview is not working. I have set the following in viewdidload.
self.MainScroll.contentSize = CGSizeMake(320, 1800);
Still it doesn't scroll. However, if i give bounce vertically, it just bounces. My scrollview is a child of the main UIview of dimension 320*600. Please guide how to enable the scroll!!
There are two ways you can get the scrolling to work.
Approach 1 (with code):
1) Pin UIScrollView to the sides of its parent view, as mentioned below.
2) Set content size of your scroll view in viewDidLayoutSubviews:
- (void)viewDidLayoutSubviews {
self.MainScroll.contentSize = CGSizeMake(320, 1800);
}
Approach 2 (pure IB, no code required):
1) Setting contentSize is not required if using AutoLayout. You need to pin your UIScrollView to the parent view as mentioned below:
2) Then add another UIView inside UIScrollView to act as a content view and pin it to the UIScrollView and move all controls inside this content view:
3) Pin content view to its parent scroll view as mentioned below:
4) Set your UIViewController's Simulated Metrics to Freeform (this is important):
5) Size your content UIView to your desired height (obviously important too):
Apple article explaining UIScrollView and AutoLayouts:
https://developer.apple.com/library/content/technotes/tn2154/_index.html
Update the content size after some delay as below.
- (void)viewDidLayoutSubviews {
[self performSelector:#selector(updateContentSize)
withObject:nil
afterDelay:0.25];
}
-(void)updateContentSize{
UIView *viewLast = [viewContent viewWithTag:100];
scrollViewAd.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, CGRectGetMaxY(viewLast.frame));
}
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.
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.
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.