Progressively reveal and slide UIView down from behind another UIView - iphone

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.

Related

How to perform an interactive animation with Auto Layout in which you interpolate between different constraints?

I'd like to have an interactive animation where a view transitions from one set of constraints to another as the user drags up/down the screen. The background image should shrink vertically (easy), and the profile image should change from being horizontally and vertically aligned to the background image to being anchored to the top and left corners of the background image. Is this possible?
Yes, it is possible, and you can see this effect in the Avvo app, for example (in the lawyer profile screen). The trick here is to smoothly transition from one set of constraints to another.
Here's an outline of how to do this:
add a UIScrollView. Add the view you want to animate as a subview to the scroll view.
Make your view controller implement
UIScrollViewDelegate
In the delegate method
scrollViewDidScroll(_:), update the constraints' constants as
needed.
Also in that method, when contentOffset crosses a
threshold value, flip to a different set of constraints, by setting
their active property to true or false.
To keep the view (the headshot image, in my example), pinned to the top as you scroll, just continuously update its top spacing constraints based on the contentOffset.y value.
Achieving a perfectly smooth transition may take some trial and error, but it definitely can be done!
Here are the screenshots showing the transition as you scroll up:

IOS UIScrollView: Cannot scroll until the end of the content

I am trying to generate a scroll controller in a window with the UIScrollView class, which will contain numerous UIButtons, placed vertically. I set the size of the scroll view equal to the current view controller's root view, so that the scroll view covers the entire visible window. Then I generate the UIButtons I am going to add to the scroll view: I add each UIButton just in the below of the previous UIButton and I add the height of the current UIButton to a variable called "totalContentHeight". Finally, I set the height of the contentSize of the scroll view to this value, in the following line of code:
self.scrollViewForNewsButtons.contentSize = CGSizeMake(self.view.frame.size.width, totalContentHeight);
totalContentHeight is equal to numOfButtons*eachButtonsHeight after I add all the buttons to the scroll view.
The problem is, in the simulator, when I run the app and scroll until the end of the last button and release the mouse, the last two buttons bounces back such that they lie outside of the visible window. It is somewhat hard to express with mere words, so here are the images:
1)This is what I get when I scrolled until the end of the content and held the content at the last possible position it could be pushed:
2)This is what I get after I released the mouse and the scroll view bounced back to its final position:
As you can see, the last two buttons are drawn outside of the visible area. It is like the scroll view's area covers the whole window plus the button area of the IPhone. I could not find a reasonable explanation for this. Am I setting the area size wrong or am I missing something else?
just set content size with calculation with your total button and its height...For Ex..
float yheight = totalButton * yourButtonHeight;
[yourScrollView setContentSize:CGSizeMake(320, yheight + 44)];
try this code...
And if you set the scrollview frame size the same as
self.view.bounds

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.

Nested UITapGestureRecognizers

If I have several views stacked one on top of the other (all subviews of each other) where each one has a UITapGestureRecognizer attached to it.
How can I make sure that the highest visible view received the gesture and not the furthest ancestor?
The tap gesture is only valid for the current view. Further the frame of your current view(-controller). You can create a blank view over the hole screen and put in there your current view lets say 200x200 px. (essentially it is both in the same view)
Now all gestures should respond to your topmost view-controller. The bad thing about that: you can't access the views below anymore.

MKMapView changes physical position in the view

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.