MKMapView changes physical position in the view - iphone

I've put an MKMapView in a view at certain x-y coordinates (x:25 y:120) at a size that's about a third of the view tall and fills much of the width (w:275, h:150). There are other elements in the view, mostly labels and buttons.
When looking at it after having it appear [edited to add: while running the app in the simulator] (pushed onto a UINavigationController stack, a detail view of a table cell) everything on the page is in its appropriate place EXCEPT for the MKMapView, which is always its height further up on the page. That is, in the case of the measurements shown above it actually puts it at x:25 y:-30. If I move it further down the page, say y:300, it still moves it up the height of the map, in this case to y:150.
Why does it keep moving? It's a terrible hack to initially position it 150 pixels farther down the view in order to have it end up at the right place.

The autosizing options needed to be set such that the top, bottom, left, right, and height were all solid (unchangeable). This may have been related to it being in a scrollview, though I'm not sure.

Related

How can I make ScrollView full screen? I placed the necessary constraints, but it doesn't work

I'm trying to make a ScrollView so that its size adjusts to the size of the text. I placed all the necessary constraints
, but when the application is displayed on the simulator, the content view starts from the safe area and also ends up to the safe area. Although I have pinned scroll view to superview and content view to scroll view.
I want the content to start not from the safe area like here ,
but from the start of the screen like here
in other words, I want to remove the blue bar from the top and bottom
Do you have any ideas how to do it?
Sometimes UITableView & UIScrollView can still show safe area even though you attach your View to top of Super View. You just need to add one line to solve this issue but make sure your ScrollView is connected to superView not safe area at the top.
Add scrollView to your ViewController and in viewDidLoad() just write:
scrollView.ContentInsetAdjustmentBehavior = .never
Check this answer for further details: Make UITableView ignore Safe Area

Unable to get the correct frame for UIViewControllerAnimatedTransitioning to UIPageViewController

I have been battling this transition animation and I am pretty much out of ideas. I am attempting something similar to going from the collection to the individual photos in the Photos app on iOS.
It all works to my satisfaction with the exception that the frame for the "big" detail view of the image is not correct. It is the right size but it is about 87 points closer to the top of the screen compared to the actual position of the image in the final state. This is pretty much the same height as what is above the "safe area" (iPhone X titles + navItem) and irritatingly close to what is also below the safe area (toolbar and iPhone X home area).
I have Googled (and "SO'd") a bunch of different solutions to similar sounding problems. E.g: UIViewControllerAnimatedTransitioning with Safe Area Insets on iPhone X
I have downloaded and perused example code from Github. E.g: https://github.com/SamStone92/CustomTransitions
It seems to me that I have something in my view (controller) hierarchy which is complicating this more than most. I would love some hints as to what might be causing the problem and how I might go about fixing it.
My hierarchy is:
NavigationController containing the root VC with a UICollectionView.
Tapping a cell transitions to a UIPageViewController for a "detail view" where I can page between items in the collection.
UIPageViewController has a bottom toolbar in addition to the navigation bar.
The content ViewController has a ScrollView with a UIImageView in it to get some zooming.
Seems like the common approach is to add the destination view to the container, force a layout pass and then get the frame. I have tried many variants of this with and without converting the coordinates. (they appear to always remain the same before and after conversion)
My Theory
I am leaning towards the UIPageViewController being the complicating factor. But I have not been able to untangle how to get the correct coordinates.
The destination view (in the animation) is not the content view but the PageVC view which in turn may or may not have added the content view, adapted it to the navigation item or the toolbar.
Seems like viewWillAppear on the content VC does not have the right coordinates. I can tell that the detail content view is getting a call to viewWillLayoutSubviews after that and also after all the animation delegation stuff has had its turn.
This is a color overlay of my main views. Grey is the top and bottom areas outside the safe area. Blue is where the transition animates to before revealing the green, underlying actual position it should have animated to.

Progressively reveal and slide UIView down from behind another UIView

I have a rectangular, menu-style view (view 1) laid across the window approx 100 px down (i.e. there is space above it in the window), and need to animate drop-down content (view 2) appearing lower down the screen from view 1. I need the animation to start at the bottom boundary of view 1 - much as with the iOS 5 notification pull-down, except from a specific point further down the screen.
I can't simply slide view 2 in from off screen, since for various reasons I can't overlay a UIView that would hide its motion until it reached the lower edge of view 1.
I've checked out this answer - Programmatically reveal a UIView - but I don't believe it's appropriate since I want the menu to slide, not be revealed from a static start point. And, as pointed out, I can't "hide" the sliding view with another view.
How do I slide down view 2 so that it is revealed as it emerges from the lower boundary of another view, similar to the io5 notification pull-down?
Contain both subviews in a superview with it's bounds clipped. So you'd have your superview (let's say app window), and within that a view (with bounds clipped). Let's call this a container view. This container would originate at whatever Y coordinate your current inserted/always visible view does, but it's height would extend tall enough to encompass the fully-expanded "sliding" third subview.
So within your container view, you'd place your first always visible view (view 1) at coordinates 0x 0y, and then you'd insert your sliding view (view 2) beneath that, with the frame y offset for view 2 set accordingly and at sufficient negative value to hide it completely by means of the over-layed view 1 and the clipped bounds of the container view.
As the user drags (or whatever means you use to disclose your 'sliding' view), the 3rd view slides down from below the always present view, but always stays within the overarching clipped view. Viola.

4 directional scrollview with paging

I need to implement a scroll view which (on a button press) will page either up, left, down or right depending on which button was pressed. Also the user can indefinately page in the same direction which will load the views in a kind of carousel. So I have 3 viewControllers.... viewController 1 is shown first....The user presses left, it shows viewController2, left again shows viewController3, left again is back to viewController 1 etc. and the same for up,down,right.
Does anyone know a good way to implement this? Im open to all suggestions.
Many thanks
Jules
Edit - second attempt at a clear explanation:
Consider this matrix.
This 3x4 matrix is the content area of your scroll view. With paging enabled, your scroll view will stop on one of these "cells", e.g. 2,1. That portion of the scroll view will be visible.
If you want each "cell" to be controlled by it's own view controller, then pre-generate all the view controllers (and their views), and then add all of their views as subviews to the scrollView.
You would populate this scroll view with whatever view you wanted to show at any given location. Set the frame of each view relative to the scrollview's origin. So if the cells were 320 pixels wide and 480 pixels tall, the frame for cell 1,3 would be CGRectMake(1*320, 3*480, 320,480).
When the scrollView ends deceleration, you can get it's contentOffset property, do some arithmetic and figure out which cell you're in.
To get the wrap-around effect, you'll have to do some trickery. You might put an extra cell at the end of each row and column, and if you find yourself in that cell, just set the scrollviews' contentOffset to the corresponding cell at the beginning of the row or column.

UIScrollView change pages after animation

Ok, I have a complicated scenario here. I have a scrollview which scrolls horizontally and contains tiles, 1 centered on the screen at a time with the user still able to see if there are more to the left or right by way of having the edges of the 2 views visible on either side. I am able to add the views programmatically to the scrollview and have paging work properly, so the user can swipe back and forth between them. Another requirement is to have an initial animation where the first view slides in, then is bounced off to the left by the second view. I accomplished this by using a series of UIView animations, and it works well.
Here is my problem: After the animation completes, you cannot scroll left to get to the first UIView that was created. I suspect that this is because it was animated out to the left of the content area of the scrollview. I have tried to increase the contentSize of the scrollview, but I still get the same behavior.Once the initial scrollview has been moved off to the left, I cannot swipe to page to it.
Is there a common pattern I could use to accomplish this in a better way?
It sounds to me like you're animating the child view's frame to the left so that the x coordinate of that first view's frame is negative, instead of animating the scroll view's contentOffset to the right. If that's the case, is there a reason you aren't just setting the scroll view's contentOffset inside an animation block? If there is a reason, what if after the animation completes you "fix up" the content offset and the frames of the child views so that none of the views are in a negative position.
But, I guess I have more questions than answers right now, so it might help to post the code showing how you do your animations to make it easier to answer your question.