Can't touch during ""Moving"" animation (Block Animation) - ios

I have a View with UIButton, UITextField, and a UIImageView for Background.
in viewDidLoad i try animate UIImageView from alpha=0 to alpha =1 using block. it's pretty basic, here's the code:
[UIView animateWithDuration:20.0 options:UIViewAnimationOptionAllowUserInteraction
animations:^{
self.movingImg.frame = CGRectMake(button.frame.origin.x,button.frame.origin.y, self.movingImg.frame.size.width, self.movingImg.frame.size.height);
}
completion:nil];
which is working fine. but during that 1.5 seconds of animation, my touch in current view seems to be disabled. i can't click on the image that is moving (animation is according to position).
Thanks in Advance

Set the alpha level to 0.01. That is the lowest Alpha according to the Apple Documentation which allows touch to work.
See Does UIButton become disabled when its alpha is set to 0.0?

Related

Button not preforming action from being tapped while animating in Xcode using UIView Animation

I have a game that I am making and I am trying to move a button named tapMe using UIView Animation but I need it to be tapeable while it is being animated.
[UIView animateWithDuration:0.5 animations:^{
_tapMe.center = CGPointMake(xRandom, yRandom);
}];
Where xRandom and yRandom are randomly generated integers and _tapMe is connected to the button, I am certain because it does move.
When you use animateWithDuration, the button's frame is moved to its final position immediately (it will be touchable there), but the presentation layer is animated, so where you see the button during the animation is not where the touchable area will be. You either need to hit test the presentation layer, or animate the button by moving it in small increments with a timer. See the answer here for more detail, UIButton can't be touched while animated with UIView animateWithDuration

Animate exit of UIView

I want to make a UIView animate when it's being closed. I tried reading the following:
http://felipe.sabino.me/ios/2012/05/10/ios-uiview-transition-effects/
iPhone UIView Animation Best Practice
iOS UIView Animation CATransform3DMakeRotation confusion
However, I'd like to make it transition from the side of the screen, as per the image in the Google Chrome app.
Is there another animation that is set for this? I was not able to find it... I'm assuming it has to do with animateWithDuration or a CATransform...can somebody point me in the right direction for this?
[EDIT]
I used the below post for an answer as well as this post:
Setting a rotation transformation to a UIView or its layer doesn't seem to work?
I was able to add multiple animations as per below:
[UIView animateWithDuration: .2
delay: 0
options: (UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
animations:^{self.view.center = CGPointMake(self.view.frame.origin.x * 3, self.view.frame.origin.y * 2), self.view.transform = CGAffineTransformMakeRotation(M_PI_4/2);}
completion:nil];
Previously I was not aware you can add multiple animations so easily. That adds rotation as well as the linear movement together.
Animate your view so it moves offscreen/shrinks/expands/fades, then do the actual removal when the animation ends.
You can do this by altering the properties of the view (position/size/offset) between a beginAnimations/commitAnimations block. UIKit will then animate these properties over the time specified.
E.g something like;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.30f];
view.transform =
CGAffineTransformMakeTranslation(
view.frame.origin.x,
480.0f + (view.frame.size.height/2) // move the whole view offscreen
);
background.alpha = 0; // also fade to transparent
[UIView commitAnimations];
In the animation end notification you can then remove the view.
I've never run Chrome on iOS, so I have to try to guess what your screenshot is showing.
Does the animation go off the screen while shrinking and turning to one side?
And do you mean you want to animate a UIViewController, or a UIView? Are you closing a view controller?
If it's a view controller, how are you managing your view controllers? Are you using a navigation controller, or are you presenting a set of modal view controllers, or some other method?

How to make a custom alert ease in/out when displaying?

I've got a custom alert dialog based on TSAlertView (https://github.com/TomSwift/TSAlertView)
However when it gets displayed its appearance is very sudden and jarring, I tried adding some animation to it using the following code however it makes no difference (the following code has no effect at all, I could change the duration to N seconds or change the animation style to anything and it has no impact):
[UIView transitionWithView:self.view
duration: 0.5
options: UIViewAnimationOptionCurveEaseIn
animations:^ { [self.view addSubview:dialog]; }
completion:nil];
Instead of adding the alert view as a subview in the animations block try changing it's alpha value. When you create the the AlertView set the alpha to zero and add it as a subview. Then, in the animation block, change the alpha value to one.
Hope this helps!

fade in/fade out UISegmentedControl in XIB

I have a UISegmentedControl set up in my XIB. I want it to appear on viewDidLoad and if the user taps the area of the screen it's in, and then to disappear if the user taps it again or to fade out if the user leaves it alone.
In looking around for how to manage this I've found a lot of stuff about fading UIViews, but not as much on fading individual subviews, and little at all on fading elements in the XIB. I tried to adapt the UIView stuff but failed.
How can I make this work?
EDIT: Okay, I've got the appearance at viewDidLoad and the fade out working. But when the user taps the area where the UISegmentedControl is (now invisible because alpha=0), nothing happens. This is the code I'm using:
- (IBAction)tapInvisibleSegContr
//This is connected to the UISegmentedControl with the action Touch Up Inside. Until now, the segmented control has been at alpha=0 since fading after viewDidLoad.
{
self.segContrAsOutlet.alpha=1.0;
[self fadeMethodThatWorksInViewDidLoad];
NSLog(#"Yup, tapped.");
}
I'm not even getting the NSLog. I've got the action hooked up to the UISegmentedControl, with the action Touch Up Inside. What am I missing?
If it is resident in a xib, just put his alpha to 0, do the properly connections: an Outlet and an IBAction for value changed
Then in the viwDidLoad right after [super viewDidLoad] write:
[UIView animateWithDuration:1 animations:^{self.mySegOutlet.alpha = 1;}];
Inside the IBAction right after you code the answer before the last } write:
[UIView animateWithDuration:1 animations:^{self.mySegOutlet.alpha = 0;}];
This is the easiest method.
Bye
In the xib set your control's alpha to 0.0, then use UIView animation methods to animate its alpha to 1.0. For example:
[UIView animateWithDuration:1.0 animations:^{
self.segmentedControl.alpha = 1.0f;
}];
EDIT: To your problem with not getting the action called, try attaching it for the value changed control event - I don't think UISegmentedControl sends for touch up inside.

UIView alpha = 0 causes touches to be dropped to the view below

So I created a glass pane or a custom UIView to handle touches. This glass pane sits on top of other views such as dummy UIButtons. When I set the alpha to be 0, the touches actually get intercepted by the views underneath the glass view. This is wrong. However, when I set the alpha to a low value like 0.2, the glass pane intercepts the touches.
The alpha setting was done in Interface Builder.
Anybody know how to set to the alpha to 0 and still get have this glass pane intercept touches?
Yes, it is standard behaviour.
For example, you can just set clear background of that UIView:
UIView *touchHandlerView;
touchHandlerView.backgroundColor = [UIColor clearColor];
In such case user wouldn't see that view - I assume that you want to do exactly that?
Yes, alpha=0.0f; and hidden=YES; have the same effect. This is very useful, because you can animate a fade-out and not have to worry about touches on the invisible object - ie you can say:
-(void)hideOverlayButton
{
[UIView beginAnimations:#"hideOverlayButton" context:nil];
[UIView setAnimationDuration:0.2];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[self.overlayButton setAlpha:0.0];
[UIVIew commitAnimations];
}
Then, when the animation is complete, the button won't respond to touches - there's no need to worry about deactivating it.
If what you want is to have invisible buttons, put a UIButton on the view, make sure it's at the front (bottom of the list in interface builder), set it's type to custom; don't set an image, background image or title. By default in interface builder you'll get alpha of 1 and a clear color.Then you can wire-up the IBOutlets in the usual way.

Resources