Animate UITextViews - objective-c

I have a View with one UITextView in the top half, one UIImageView on the bottom half and a button in the middle, between them. What I'm trying to do is every time I press the button, the UITextView must change the text (it gets it from a sqlite db). I managed to do that, but now I want to animate the text change. So I want the UITextField to fade out to the left, then fade in from the right with a the new text inside.
Now i followed the ViewTransition documentation and created a second UITextView so I can animate between them. The only problem is that animation happens to the entire view. So even the image and the button slides in every time. I just want to animate the text view(s).
How would i go about doing that?

[UITextView beginAnimations:nil context:NULL];
[UITextView setAnimationDuration:0.5];
self.firstTextView.transform = CGAffineTransformMakeTranslation(-100, 0);
self.secondTextView.transform = CGAffineTransformMakeTranslation(-100, 0);
[UITextView commitAnimations];

Related

UITextView not Responding to Touch Events after Animation

I am performing an animation to correctly keep the UITextView at the bottom of the screen if I expand the view. For some reason if I perform the animation, the UITextView stop responding to touch events, so there is no keyboard that will show up.
All I am doing is:
CGRect newSendTextView = self.commTextView.frame;
newSendTextView.origin.y = (newSendTextView.origin.y + (height - self.defaultSize.size.height));
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.5];
self.commTextView.frame = newSendTextView;
[UIView commitAnimations];
I know the UITextView is still on the screen after I do the transformation since I colored the UITextView background a bright blue, but it doesn't want to respond to any touch events.
If I comment out self.commTextView.frame = newSendTextView; so that it doesn't move, the touch events register.
I have no idea why this happens, I tried
[self.commTextView becomeFirstRespond];
and I have checked if isEditable and isUserInteractionEnabled is set to 1 and it is.
I guess, new position of TextView might be getting overlayed by other view. Check any other View is having same frame on your TextView new position. Use clipsToBounds property to find it.

UIView clipToBounds is not stopping a subView receiving touches outside the parent view

I have two UIViews. I'm using one to contain the other so that I can slide one inside the other. I'm encountering an issue where even though a subView is clipped to the bounds of its parent, it is still receiving touch events and blocking access to other underlying views.
I have three screenshots that show the layout. I've coloured the parent green and the child red.
The idea is that the user clicks "View" and the subView slides up. When the subView is in the default position, the UITabBar is covered and cannot be clicked. You can see this in the first image where the red view is present at the bottom. When the subView is moved to the top, the UITabBar can be clicked as it's now visible. In the third image, I've show what it's like with clipToBounds enabled on the green UIView.
I've enabled clipToBounds, so I cannot understand why the subView is blocking the underlying UITabBar. Is my understanding of clipToBounds completely wrong??
Using clipToBounds only affects the visual layout of a subView, not the logical layout. This means that whilst my subView isn't visible to the eye, it's visible to touch.
I've worked around this issue by animating the size of the subView rather than its position. In my code below, the stationProximityView is the subView. I animate its size by 40 pixels to bring the black title back into view.
[UIView beginAnimations:#"stationProximityBar" context:NULL];
self.stationProximityView.view.frame = CGRectOffset(self.stationProximityView.view.frame, 0, -40);
[UIView commitAnimations];
When I no longer need it, I animate it out of view.
[UIView beginAnimations:#"stationProximityBar" context:NULL];
self.stationProximityView.view.frame = CGRectMake(0 ,0, 320, 500);
[UIView commitAnimations];
If the user taps the view button, the entire subView is shown:
[UIView beginAnimations:#"stationProximityBar" context:NULL];
self.stationProximityView.view.frame = CGRectMake(0,460,320,40);
[UIView commitAnimations];
Dismissal causes the view to be hidden in the same way as the small bar.
[UIView beginAnimations:#"hideStationProximityBar" context:NULL];
self.stationProximityView.view.frame = CGRectMake(0,0,320,500);
[UIView commitAnimations];
At the moment, this code is only being tested on the iPhone 5, so the hard-coded height of 500 would causes issues on previous iPhone models.

How can I implement a pointer arrow on a toolbar in iOS?

I'm looking to implement a pointer arrow above the currently selected toolbar icon much like the design found in Reeder and Instacast:
The pointer arrow should move across smoothly when another toolbar item is pressed. I need to be able to choose which items cause the arrow to move, as featured in Instacast and Reeder, where only certain items change the arrow position.
Can I do this without too much overhead and a lot of UIKit subclassing?
This shouldn't be too bad: just take an image of the little triangle like you have in your question, and put it in a UIImageView that sits above the toolbar.
Then set it up so that when the action: for the relevant toolbar button is called, the UIImageView slides so that it's in the right place, with animation. Something like:
[UIView beginAnimations:#"TriangleAnimation" context:NULL];
[UIView setAnimationDuration:0.25];
triangleImageView.frame = //new location here
[UIView commitAnimations];

How can I start animating an UILabel from a particular location in iPad?

I need to start animating a UILabel when a button is pressed... the animation should start from the position of the button.
How can I achieve this?
i.e moving label from one end of the screen to another end.
This is acheviced with UIView's animateWithDuration methods, which can be found in the documentation here.
A very simple example which should be called when your button is pressed:
[UIView animateWithDuration:0.5 animations:^{
// set new position of label which it will animate to
myLabel.frame = CGRectMake(x,y,width,height);
}];

UIColor groupTableViewBackgroundColor is transparent

I have a grouped style UITableView on my navigation stack, and when I click on a cell, I push a UIDatePicker onto the stack. The problem is that I want this custom view to have the same background color as my table view.
I tried setting the background color of my custom view like:
datePicker.backgroundColor = [UIColor groupTableViewBackgroundColor];
But this comes out transparent. I also tried modifying the underlying CGColor object to have an alpha of 1.0, which caused the background color to be black.
The following does work as expected:
datePicker.backgroundColor = [UIColor lightGrayColor];
But, of course, this color doesn't quite match the grouped table background color.
Am I going about this all wrong? I found a similar post about this here, but no helpful response.
What do you mean you "push a UIDatePicker onto the stack"? Why dont you try animating the UIDatePicker into view?
when the view loads, create the picker and set the frame off screen, such as
[picker setFrame:CGRectMake(0,960,320,216)];
then instead of "pushing" the picker, animate it into view like:
[UIView beginAnimations:nil context:NULL];
[picker setFrame:CGRectMake(0,200,320,216)];
[UIView commitAnimations];
And when you want to dismiss the picker, just hide it like:
[UIView beginAnimations:nil context:NULL];
[picker setFrame:CGRectMake(0,960,320,216)];
[UIView commitAnimations];
If you need to, you can also add a toolbar with a "done" button to dismiss the picker, works great for me.
If the contents of the picker are going to be displayed on the table, then you can set the frame of the table in that animation sequence. in the first one, make the table half the size (like 150 for my example would work perfect), then in the hide sequence, make the table the original size (415 for this example). And when you hide the picker, call [tableView reloadData]; to refresh the table.