How do I get the UIPickerView to slide up over another view? - iphone

I am looking for a way to slide a UIPickerView (and UIDatePickerView) up over a view (UITableView in particular) when a particular button press takes place.
I understand how to get the events for clicks into the UITableView, but there doesn't seem to be a good way to have the UIPickerView slide up on top of it...
All the examples I have seen so far just have it snapped to the bottom of another view and I am able to do this without issue.
Thoughts?
Thanks in advance.

Modally presented view controllers slide up from the bottom to cover the current view.
See the documentation for -presentModalViewController:animated: in the UIViewController Class Reference. You would invoke this method on your UITableViewController and pass the UIPickerViewController as the first parameter and YES as the second.

An example of what Ben mentions above (Animation Blocks) is the following, which will animate to a subview.
UIWindow *window = [[Director sharedDirector] window];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:(UIViewAnimationTransitionCurlDown)
forView:window
cache:YES];
[window addSubview:aView];
[UIView commitAnimations];

Have you tried using UIView's animation blocks do do this? See the Apple docs on +[UIView beginAnimations:context:] and +[UIView commitAnimations]. Basically, wrap your calls to display the UIPickerView in these calls, and you can slow it down a bit.

Related

Flip animation between two UIViews on a UIViewController

I have two UIViews on my view controller. I wanted to flip between the two views on user touch. Everything is fine except the animation I tried two methods, first was:
[UIView transitionFromView:frontView toView:backView
duration:01.0 options:UIViewAnimationOptionTransitionFlipFromRight
completion:NULL];
This was animating the view but actually animating the whole view controller's view, while I wanted only the portion where my views are, which is about 320x200 in the centre of the screen.
Then I tried the other option, which is:
[UIView animateWithDuration:1.0 delay:0.0
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
[frontView removeFromSuperview];
[self.view addSubview:backView];
} completion:nil];
But this is not animating the views at all. Just switching the views instantly without any animation. Can anyone please help me in understanding where I am wrong or need to change. Thanks very much for your time and consideration.
Awhile after I posted my question I found a great answer for this query which you guys can look at :
How to flip an individual UIView (without flipping the parent view)
The trick is to use third UIView as container view and then adding the views, which needs to be animated, as subviews on it. That does the trick in my case. Remember that I am using the first method that I mentioned in my question. Thanks everyone for your time.

Issue with animation of UITextView in a UIView

I have a setup in which I have my main UIView, within this I display another UIView which appears to slide & expand until fully in view. Within this new view I have a UITextView, however when I run the animation to make the UIView appear it doesn't seem to apply the animation to the UITextView. The effect of this is that the UITextView just appears in its final position straight away, the rest of the UIView then slides into place. Is there a way to make the animation apply to the widgets inside the view as well?
Here is the code I'm using at the moment.
[self.view addSubview:innerView];
[innerView setFrame:CGRectMake(29.5,127,261,0)];
[textView setFrame:CGRectMake(20,20,221,0)];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5.0];
[innerView setFrame:CGRectMake(29.5,127,261,275)];
[textView setFrame:CGRectMake(20,128,221,129)];
[UIView commitAnimations];
Please can someone help me out? I've been playing around with this problem for a long time now with no luck at all.
I had similar behavior in one of my apps. It was due to the autoresizingMask on a UITextView. Also make sure your top UIView does not have autoresizesSubviews option enable as it will influence the behavior of your UITextView on animation.

How to make controls fade away on iPad/iPhone as per interface guidelines

THe HIG makes a statement that on the iPad, to consider fading away controls similar to how the built in photo app does it.
How is this accomplished?
In my case I have an image occupying the majority of the screen with a tab bar and potentially tool bar and potentially other controls. How do I fade everything away except the image. And bring it back if the user touches the screen.
Thanks
I think you have 2 alternatives. First, by core animation, you can set the alpha to 0 in about 0.5 or 1 second, the other way is to set the toolbar and navigation bar to hidden. If you're working with a navigation controller, you can call
[self.navigationController setToolbarHidden:YES animated:YES];
or
[self.navigationController setNavigationBarHidden:YES animated:YES];
this probably do what you want.
"And bring it back if the user touches the screen."
For this, you may implement methods like:
– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
– touchesCancelled:withEvent:
this will work if you're working on a UIViewController subclass only.
Good question. There are a number ways to do this as some view controllers may have built-in methods for hiding (e.g. UINavigationController). For anything that is a UIView, or subclass of, I would recommend something like the following:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
//Fade out a UIImageView over a one-second duration
imageView.alpha = 0.0;
//Fade out the TabBar, assuming it's owned by the app delegate
appDelegate.myTabBar.tabBar.alpha = 0.0;
[UIView commitAnimations];
Hope this addresses your question.
Andrew

How do I make the modal view only come up half way?

So I have an app where you play a game, and at the end it asks you your name for recording of the high score. I would like to use a modal view to accomplish this, but I am experiencing some hiccups along the way. So far, all I have is the modal view sliding up all the way to the top of the screen, but there isn't anything there yet, it's just blank:
UINavigationController *navController = [UINavigationController new];
[self presentModalViewController:navController animated:YES];
I have seen on several other iPhone apps, the ability to make the modal view come only half way up the screen (or less) and then have a textfield where you can receive input, such as for my high score list. How would I go about restricing the size of the modal view? And perhaps adding a textfield onto it? Any help would be appreciated! Thanks
What makes you think presentModalViewController was used?
You can do this quite easily with an UIViewController and animation.
Using Animation, a sample would look like something like this:
//Move Screen UP:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y - kTextView_Keyboard_Offset), self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
Where the "kTextView_Keyboard_Offset is defined in my Contants. You would specify/replace with your Offset value equal the number of pixels in the direction that you would like to move.
Define a full-screen view with a transparent background - then put the obscuring content wherever you like.
Then you just bring it up as you would any other modal view.

Flipping UIView inside UIScrollView

In photo app of iphone you can see smooth scrolling to the other picture with finger flicking. Is it possible to allow individual view to be 'flipped' (or rotated) to show its back side ? Found that UIScrollView is used for smooth scrolling and found the code for flipping UI. Outside of UISCrollView I got the flip to work using the code below. But once inside UIScrollView this doesn't work - it executes but UI never switches.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[UIView setAnimationDuration:1.0];
[myView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations];
Perhaps this is not suppose to work this way. What is the recommended way or technique to have flippable individual views inside the UIScrollView ?
Never mind. It does work. Once inside UIScrollView there were several UIViews and I needed to make sure I grab the pointer to current UIView. The above code works in this case as well. I was doing a flip on a view which was hidden :)