iOS 11 UINavigationBar Position Loses Status Bar Height During Transition - uinavigationcontroller

This bug has cropped up in iOS 11. There is a UINavigationController embedded as a child UIViewController of another UIViewController. There's a UIPanGestureRecogniser setup that affects the y axis of the child UIViewController's view's frame allowing you to drag it down to reveal the UIViewController below
The problem that's cropped up is that now as soon as the UIViewController's frame gets adjusted to move it downwards iOS seems to remove the inset on the UINavigationBar for the UIStatusBar, which results in an unpleasant jerk upwards.
How do I prevent this from happening?

Related

iOS 11 iPhone X toolbar not respecting safe areas

I have noticed that in the simulator using iPhone X, the tabBar increases dimension vertically to respect the safe area on the bottom of the screen. However toolbars added in storyboard do not and still maintain their default 44 height which causes the toolbarItems to be cutoff on the edges.
How would I duplicate the tabBar behavior for the toolbar on iPhone X without customizing the toolbar?
In order to be able to constrain items to the safe area in a storyboard, you need to enable "Use Safe Area Layout Guides" on the storyboard, in the Interface Builder Document section:
Once you've done that, you can, as mentioned in the other answer, constrain to the Safe Area:
The solution is to change the vertical constraint in storyboard on the bottom and sides to the safe area rather than container margin:

iOS10 storyboard layout issue

We have a table view with prototype cells in a storyboard that work well in iOS 7 to 9. The content of the cells is layed out with AutoLayout.
In iOS 10, the prototype cell does not display its content. The cell is black.
If I run the view debugger and show the clipped content, I see the cell's content being shown. Part of it is within the cell's bounds, part of it outside. Even then, the content's position does not correspond to the layout constraints.
Also, when looking at the view hierarchy on the left hand side of the view debugger, I can see that the cell has no children.
Deleting this line fixed the issue:
expiryDetailsTableViewCell.translatesAutoresizingMaskIntoConstraints = NO;

Android : negative margins behave differently on different versions

I am writing an application where I need to move a view from top to bottom but only when user moves it downward. To move this view I have a button below the view to drag. So initially I place the view beyond top of the view i.e. with negative margin equals the height and only the drag button is visible at the top to user. I see that this works perfectly on Lollipop and view is just at the position where bottom of view matches the top of screen. When I try it on Kitkat and lower versions, the view goes more towards top than the edge of screen. I have this everything in a RelativeLayout.
To show that view is dragged downward I am manipulating bottomMargin and topMargin properties on view.
Has anyone came across similar problems? Thanks in advance.

dynamic resizing of UICollectionView using intrinsic size within an autolayout

I am trying to implement a calendar using UICollectionView which has a similar scrolling behaviour to the built in calendar app when changing months. At the moment the view is flickering as the resize occurs between months.
I am using a UICollectionViewScrollLayout with a UICollectionView with 10000 indexes in 1 section. The cells are filled by calculating the day for an index. The problem I am having is when trying to resize the view to fit the correct number of weeks for the month, the collectionview doesn't appear to draw in the cells quickly enough as the scrolling and view size change happens. Having slowed the animation down, as the view size changes, it appears that cells are being removed too early from the view. This happens both with a reducing and enlarging the view. Ie, as they are about to scroll off the view they are removed before scrolling out of the view.
The layout is all done using autolayout and there is a fixed view above and then a resizable view below. As the size of the collection view changes the view below changes to fill the space. The only way I seem to have managed to achieve this behavior it is by changing the intrinsic size as per the code below. I have tried changing the frame/bounds but it doesn't seem to work with autolayout. Am I going about the resizing of the view in the right way?
Should I be moving the behaviour to the viewcontroller and change the constraints pinning the height instead.
// Scroll the view to the date given.
-(void) moveViewToDate:(NSDate*) date
{
NSIndexPath *indexPath=[self indexPathForFirstDayInMonth:date];
[self scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionTop animated:YES];
[UIView animateWithDuration:0.25f animations:^{
self.isize=[self weeksInViewForDate:date];
[self invalidateIntrinsicContentSize];
[self.superview layoutIfNeeded];
}];
}
-(CGSize)intrinsicContentSize
{
return CGSizeMake(322,self.isize*46);
}
I finally worked out what was going on. Since I was committing an animation which was changing the size of the view and doing a scroll, the two seperate animations where conflicting with each other.
I eventually rewrote the collection using UIScrollView but had the same problem. I got round it by placing the UIScrollView in a UIView. The UIView was resized using a constraint on the height which was animated.

UISearchBar in UINavigationBar changes width when rotating orientation

This is driving me crazy. I am creating a splitview app on iPad.
I have created a searchBar inside the UINavigationBar - something like this...
UISearchBar *searchBar = [[UISearchBar alloc] initWitFrame:CGRectZero];
[searchBar setPlaceHolder:#"Search"];
[searchBar sizeToFit];
[searchBar setDelegate:self];
[self.navigatioItem setTitleView:searchBar];
this works just fine for me displaying the UISearchBar like this...
I also have this UIBarButtonItem set to show Master navigation controller in sidepane.
The problem happens when the device rotates to landscape and the UIBarButtonItem gets hidden. Then the searchBar appears like this...
there is some space on sides which appears to be there since the barButtonItem got hidden and the size of search bar couldn't be updated.
Furthermore, when I rotate the device again, here's what happens to UISearchBar
How can I update the size of searchbar once it has been added to UINavigationBar. Even using autoResizingMask does not work.
searchBar.autoResizingMask =UIViewAutoresizingFlexibleWidth;
What am I doing wrong over here?
I had about the same problem (it wasn't searchbar, but some UIView), and that's how I solved it:
Try creating it with fixed size that won't change. I mean if your navbar minimum size is (for example) 320pt, and barbutton is about 30pt, and you need searchbar to be placed right in the middle (which, BTW is not standart, AFAIK), you'd have to make it 320 - (30+10)*2 = 240pt. Searchbar would be placed right in the middle and will have enough place left free.
This way it will neither change it's size, nor it will affect other items.
Or I would suggest you placing it at right position, not in the middle.
Hope it helped.

Resources