Issue with animation of UITextView in a UIView - iphone

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.

Related

How to make the textfield move up when keyboard covers it up

I have an application in which I have 2 textfields and a textview. When I click on the first textfield my keyboard popsup and theirs is no problem but when I type in the second textfield my keyboard popsup and covers the textfield.
I want that when I click on the second text field, the textfield should move up little bit so that I can type in and I have a textview. But I have written code for textview so that when I type in textview it automatically moves.
The problem is with textfield. How can I solve this problem?
Consider using a UITableViewController. Otherwise implement UITextFieldDelegate and move your UIView to the desired position in the - (void)textFieldDidBeginEditing:(UITextField *)textField method.
Check out the link below - the solution is written by Micheal Tyson. It addresses UITableView and UIScrollView, can be easily changed and works just as a drop-in component. I'm using it and it works well.
A drop-in universal solution for moving text fields out of the way of the keyboard
Create two methods like given below , first one is for bringing the view slightly upwards, and second one is to bring the view to its original position back
First method:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.3];
self.view.transform = CGAffineTransformTranslate(self.view.transform, 0, -175);
[UIView commitAnimations];
Second method:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.3];
self.view.transform = CGAffineTransformTranslate(self.view.transform, 0, 175);
[UIView commitAnimations];
[self.destext resignFirstResponder];
Call these methods on textfieldEditingDidbegin and DidEndonExit
Add the view to a UIScrollView. Then use the UITextFieldDelegate methods to set the contentOffset of the scrollView when textField is tapped. Reset the contentOffset when the user has finished entering text.
I have created a simple subclass of UIView containing UITextView and a send button that moves up when keyboard shows and moves down when keyboard hides. In addition to that, UITextView resizes according to the amount of text in it.
Have a look at here:
https://github.com/kerrygrover/KBTextView
An obvious one that you've probably tried already, but one that took me a while to latch onto, is to change from landscape to portrait.

UIView loses background when animated up

I am working on an iOS app and am having trouble with a really tall UIView (2400px tall). The UIView contains a really long form that's been broken down into 5 parts. As the user completes one part of the form, I would like to slide the UIView up to reveal the next part. I present the UIView modally.
The problem that I am having is that when I slide up the UIView, the background slides up along with the objects in the first section and the next section is left with a clear background. The code I use to slide the UIView is:
- (IBAction)slideUp {
// Slide the view up the screen to reveal the next section
CGRect frame = self.view.frame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.75];
frame.origin.y = -480;
self.view.frame = frame;
[UIView commitAnimations];
}
All of the objects in the really tall UIView slide up fine, I'm just losing my background color. Any idea why?
Thanks!
Is your background being rendered by some sort of "background view" that's sized to fit the screen?
In any case, you should probably use a UIScrollView with scrolling disabled instead of a really long UIView. You can then simply animate the contentOffset property to scroll the controls up, but the scrollview itself can simply be screen-sized.
Instead of using self.view.frame, i would highly recommend you create an IBOutlet for the really long view so that the code looks like self.longView.frame.
This will help making it clear which views you are working with.
Right now i am betting that you are animating the wrong view.

How do I make a UIPickerView in a UIActionSheet

Just want to know how I would make a UIPickerView in a UIActionSheet with a simple array.
Ok well I actually found out how to put it into an action sheet but I like your way better because it applies more to my app, thanks, but I want to also know how put the options into the UIPickerView, I am just hung up on that part of that. I already have an array with the colors: red, green, blue, yellow, black, etc in it but I want to know how to put that into the pickerview if I have already used initwithframe:? Please anyone help I know it is a stupid question but I'm racking my head on my $$$$$$ Macbook.
You don't want to do that. Instead, create your UIPickerView in Interface Builder and connect it to an Outlet in your view controller. Add it as a subview of your main view and set its frame coordinates so that it is offscreen just below the bottom edge, x=0, y=480.
Then, when you want to display the picker, animate it onto the screen with something like:
[UIView beginAnimations:nil context:NULL];
[colorPicker setFrame:CGRectMake(0.0f, 416.0f, 320.0f, 216.0f)];
[UIView commitAnimations];
And then hide it when you're done picking with this:
[UIView beginAnimations:nil context:NULL];
[colorPicker setFrame:CGRectMake(0.0f, 480.0f, 320.0f, 216.0f)];
[UIView commitAnimations];
This will cause your picker to slide up from the bottom animated and slide back down when you're done.
I don't think adding a picker to a UIActionSheet, if it's even possible, is advisable.

UITableViewCell Custom Drawing and Animating when Entering Edit/Reorder Mode

I am trying to do something very similar to this post. Starting with Atebits Fast Scrolling in Tweetie post I have a UITableView subclass that does all of it's drawing in the drawRect: method of it's contentView. This works perfectly and is super fast. What I am trying to do now is animate the transition from editing to not-editing.
An example of what I am trying to achieve would be a situation with some text right aligned in the cell. When entering edit mode, the contentView shifts right to allow room for the editing control but the text shifts offscreen on the right as well. If I simply call [contentView setNeedsDisplay] in layoutSubviews I can readjust the right aligned text but it just jumps to it's new position.
How can I get the transition to animate?
Your layoutSubviews should look like this:
-(void)layoutSubviews {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
/* Change offsets here. */
[UIView commitAnimations];
}
You may also need to add to applicationDidFinishLaunching:
[UIView setAnimationsEnabled:YES];

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

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.