Typing while animation UITextView - iphone

I'm trying to have a variable-height UITextView which changes size to accomodate its contents, but when the frame changes in the size-change animation, one or two keystrokes aren't captured in the UITextView. The animation duration is 0.1s, and typically it only misses one letter when you're typing fairly fast. It is, however, very consistent in missing letters when the animation happens. The following animation block occurs within the textViewDidChange: delegate message:
[UIView animateWithDuration:0.1 animations:^{
[textView setFrame:CGRectMake(...)];
}];
I've Googled and searched on SO, but so far nothing has come up. Has anyone else encountered this?

By default UIView animations disable user interaction for animated view, so possibly (sorry cannot test it now) explicitly enabling user interaction will solve your problem:
[UIView animateWithDuration:0.1
delay:0.0
options: UIViewAnimationOptionAllowUserInteraction
animations:^{
[textView setFrame:CGRectMake(...)];
}
completion:^(void){}];

Related

Make a Flip animation (or something similar) when I reload the content of my UIWebView

In one of my project i'm using only a UIWebView. I need an animation (for example a flip) when I reload my webView with another content... Is it possible to create a flip animation (or something similar)? I must create a fake controller to get it?
Solutions?
Thanks
You can always do the +transitionWithView:duration:options:animations:completion: method with the web view.
[UIView transitionWithView:self.webView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft | UIViewAnimationOptionAllowAnimatedContent animations:
^{
[self.webView loadHTMLString:#"<strong>Hello world</strong>" baseURL:nil];
} completion:^(BOOL finished)
{
}];
This method is basically a way of saying: "change the contents of this view, in animated fashion". So it takes an snapshot of the current state, performs the animation (be it a flip, curl, etc) and then inserts an snapshot of the new state.
But notice that I've used UIViewAnimationOptionAllowAnimatedContent, this forces the animation to not use a snapshot for the new state of the view, because setting loadHTMLString does not change the view immediately, so we need to force it to use the live context of the view instead of a snapshot.
The weather app in iOS (pre 7) uses a similar method for alternating between the current weather and the picker for other regions/options when clicking the "i" on the bottom.
I think that you don't need to create a controller for that. You can simply add something like that:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.80];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:yourView cache:YES];
[UIView commitAnimations];

scrollViewWillEndDraggin:WithVelocity:targetContentOffset delegate method bug

I am implementing a UIScrollView and its delegate in a UIViewController. It scrolls in the horiztonal way.
WHat I want is to set "magnetism" when the view is dragged and is stabilizing.
to do that, I am listening to the delegate, specially the method mentionned in titled.
It returns me the offset of the final destination.
then I make the scollview display the view which correspond to this destionation with setContentOffset or setvisiblerect methods.
I also NSlog the entire method to catch the bugs.specially right after calling the method I have a nslog which confirmed me/or not, if the method is triggered.
problem : when I build&run, the first nslog is triggered an average of 3 times by dragging.
so the entire effect looks very strange and I can't figure out whether or not it works.
I have found very little things about this on the net. So it would be a great help if you had some clues.
cheers
I am kind of desperate :/
So you want the scroll view to snap to a valid selection when the user is done dragging? You should be able to implement this using the
- (void)scrollViewWillBeginDragging:(UIScrollView *)thisScrollView
and
- (void)scrollViewWillDidScroll:(UIScrollView *)thisScrollView
methods. Without seeing your code I can't tell you exactly how to go about this, but I would recommend keeping track of the thisScrollView.contentOffset.x in a variable, and doing some arithmetic to move the scrollView with a
[UIView beginAnimations: #"anim" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
[UIView commitAnimations];
call to move it to the appropriate spot.

iOS UIView block animations stop actually animating

I've got a weird issue with using UIView block-based animations. My app contains an assortment of images in scroll views and, after a while of using the app on the device, all animations in UIView animation blocks (such as the one below) stop animating. The animation is processed (in the example code below, the pageView does move) but this change isn't animated and happens instantly.
[UIView animateWithDuration:0.5 animations:^
{
self.pageView.center = CGPointMake(self.view.frame.size.width/2, 704.0/2);
self.pageView.transform = CGAffineTransformIdentity;
}
completion:^(BOOL finished)
{
NSLog(#"complete");
}];
Has anyone else experienced similar behaviour? I'm using an iPad on 5.1 and am wondering if it could be down to iOS version?
Thanks,
Michael
Check your memory usage. I am seeing the same thing you are -- eventually all of the animations stopped working. The animations didn't even run for me, and completion blocks weren't firing.
I found that I was holding on to a number of UIImageViews that weren't visible anymore because I wanted to re-show them later. Removing them and freeing up the UIImage made the problem go away. I now need to figure out how I'm going to get back the images but at least the animations work as expected.
When you're using transforms, animations can have a really unpredictable behavior if you use them separately. To avoid this, you ought to concatenate all your transforms into a single one via CGAffineTransformConcat and animate that single transform.
Try using some animation options and see if that helps?
For example here I'm letting the user interact and letting views redraw themselves during an animation :
[UIView animateWithDuration:0.5
delay:0
options: UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionAllowAnimatedContent
animations:^ {
self.pageView.center = CGPointMake(self.view.frame.size.width/2, 704.0/2);
self.pageView.transform = CGAffineTransformIdentity;
} completion:^ (BOOL finished) {
} ];

Animation is effecting every view even after calling commitAnimation

I am developing a Cocos2D game. On a stage a show a UIView giving users a list of tasks to perform. There are text fields which I move up or down using Animation. My code is below.
[textField setFrame:CGRectMake(textField.frame.origin.x, textField.frame.origin.y, textField.frame.size.width, textField.frame.size.height)];
[inviteButton setFrame:CGRectMake(inviteButton.frame.origin.x, inviteButton.frame.origin.y, inviteButton.frame.size.width, inviteButton.frame.size.height)];
[headingLabel setFrame:CGRectMake(headingLabel.frame.origin.x, headingLabel.frame.origin.y, headingLabel.frame.size.width, headingLabel.frame.size.height)];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelegate:self];
[textField setFrame:CGRectMake(textField.frame.origin.x, textField.frame.origin.y-50, textField.frame.size.width, textField.frame.size.height)];
[inviteButton setFrame:CGRectMake(inviteButton.frame.origin.x, inviteButton.frame.origin.y-50, inviteButton.frame.size.width, inviteButton.frame.size.height)];
[headingLabel setFrame:CGRectMake(headingLabel.frame.origin.x, headingLabel.frame.origin.y-30, headingLabel.frame.size.width, headingLabel.frame.size.height)];
[UIView commitAnimations];
[self.view.layer removeAllAnimations];
Problem is that even after user is done and he presses the cancel button to remove this view from the super view, every view including UIAlertView and other subviews appearing in my map after removing that view are effected by the animation i used to move text fields and label up or down. UIAlertView is using same Animation to show up and so is happening other subviews. Can anyone please tell me why this is happening?
Best Regards
You have to set the animationID to a unique value in the beginAnimations:context: method.
See the official doc
Also this doc states:
Use of this method is discouraged in iOS 4.0 and later. You should use the block-based animation methods to specify your animations instead.

Troubles with UIView, animateWithDuration and beginFromCurrentState

I have a custom view that has to track the user's location. I put the following code in touchesBegan, as well as in touchesMoved:
[UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
cursorView.center = locationOfTouch;
} completion:^(BOOL finished){}];
It seems fairly straightforward to me. I'd expect the view to always animate to the user's current location, even if that location is changed and the view is still animating (because of the beginFromCurrentState option).
Yet, each animation finishes completely. They don't 'transition' to the new animation, no they finish first, then they start the new animation.
I tried adding this line in touchesMoved:
[cursorView.layer removeAllAnimations];
Doesn't do anything. No animation is cancelled. Any ideas?
with [cursorView.layer removeAllAnimations]; you access the layer of the view but you have set the animation not to the layer but the view directly.
Try:
[UIView beginAnimations:nil context:NULL]
[UIView setAnimationDuration:0.2];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
cursorView.center = locationOfTouch;
[UIView commitAnimations];
and leave out the removeAllAnimations and it should transition from current state.
Looks like this is a derivative of another question you asked that I just answered, but the same idea applies.
You don't need to use blocks to do this. Just wrap your setCenter in a UIView animation. Like this:
[UIView beginAnimations:nil context:NULL]
[UIView setAnimationDuration:0.2f];
cursorView.center = locationOfTouch;
[UIView commitAnimations];
Keep in mind that 0.2 seconds is pretty fast. It may appear to be "jumping" to the position. To confirm, set the duration to something like 2.0 seconds and see if it's animating.
Best regards.
Technically, the view should automatically animate with a default time of 0.25 seconds. That is what the manuals say, however, I'm currently on here because the manuals don't seem to be very accurate regarding animation.
Also, the beginAnimations call is being phased out, you might want to use a CATransaction instead