animated UIButtons are clickable at destination before they reach destination - animation

I have a UIView that contains a couple UIButtons that I am animating from offscreen to onscreen. I find that the region where they are heading is clickable before they reach it. The animation is pretty simple, so I'm wondering if there is something obvious that I am missing in terms of telling the code to not treat the button as if it is at the final destination (I'm not sure if that is supposed to be the expected behavior and the animation is purely a visual while the clickable region is instantaneously at the destination; I wouldn't expect it to be).
Here is the code I use to animate it. It's basically switching out a sub panel and bringing back a main panel with buttons:
// switch back to main abilities panel
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: kFadeInTime];
CGRect rect = CGRectMake(
480.0f,
mAbilities.mSubPanel.frame.origin.y,
mAbilities.mSubPanel.frame.size.width,
mAbilities.mSubPanel.frame.size.height);
mAbilities.mSubPanel.frame = rect;
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: kFadeInTime];
[UIView setAnimationDelay: kFadeInTime];
rect = CGRectMake(
kAbilitiesBorderX,
mAbilities.mPanel.frame.origin.y,
mAbilities.mPanel.frame.size.width,
mAbilities.mPanel.frame.size.height);
mAbilities.mPanel.frame = rect;
[UIView commitAnimations];

As a workaround you can disable user interaction with your panel before animations and reenable it when animation finishes:
// Animation compete handler
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
mAbilities.mSubPanel.userInteractionEnabled = YES;
}
// Animating panel
mAbilities.mSubPanel.userInteractionEnabled = NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: kFadeInTime];
[UIView setAnimationDelegate: self];
CGRect rect = CGRectMake(
480.0f,
mAbilities.mSubPanel.frame.origin.y,
mAbilities.mSubPanel.frame.size.width,
mAbilities.mSubPanel.frame.size.height);
mAbilities.mSubPanel.frame = rect;
[UIView commitAnimations];
If you're targeting iOS4 you can (and as specs say should) use block-based animation api:
[UIView animateWithDuration:5.0f delay:0.0f options:UIViewAnimationOptionLayoutSubviews
animations:^(void){
CGRect rect = CGRectMake(
480.0f,
mAbilities.mSubPanel.frame.origin.y,
mAbilities.mSubPanel.frame.size.width,
mAbilities.mSubPanel.frame.size.height);
mAbilities.mSubPanel.frame = rect;
}
completion:NULL
];
While animating using blocks user interaction is disabled by default - you can enable it by setting UIViewAnimationOptionAllowUserInteraction flag in options parameter:
... options:UIViewAnimationOptionLayoutSubviews | UIViewAnimationOptionAllowUserInteraction ...

Related

Bar Button Item Fade In/Out?

Is there any way to fade a bar button item, as there is no .alpha attribute to set. I'm interested in fading a button out and fading another button in to take its place on the navigation bar. Is there any way to do this?
EDIT: I am trying to fade the top right Bar Button Item
I understand fading is usually accomplished with the .alpha as I stated before.
My issue is for a Bar Button Item there is NO alpha attribute.
As seen here:
As opposed to a normal button where there is an .alpha attribute:
How can I fade a Bar Button Item?
Easy. You would have to create an outlet for them both then create if statements or whatever method you want to initiate the fade in/ fade out animations:
- (void) animateButton {
button1.alpha = 0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:.5];
button1.alpha = 1;
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
[UIView commitAnimations];
}
- (void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
button1.alpha = 0;
[UIView commitAnimations];
}
swift
viewDidLoad {
self.button1.alpha = 1
self.button2.alpha = 0
}
When you call Animation Code:
UIView.animateWithDuration(1.0, animations: {
self.button1.alpha = 0
})
// Changing buttons based on UIControlState: You can also do this in storyboard by dragging a bar button item to your view controller and ctrl+drag to your .h file to create an outlet and then commit your animations or code based on what you want.
UIImage *backButtonImage = [[UIImage imageNamed:#"button_back"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 6)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

UiScrollView scrolling UiView

in my viewcontroller entered all the objects in a scrollview. One of the buttons inside the scrollView creates an animation.
The scrollView get off the page -80.0 orgine.y
So far so good .. Now I want that when you click on the button the scrollview and then goes back down to -80.0 to +80.0 automatically returning to its original position so ... Can you tell me the best method for you to have this?
This is the action that fulfills my button when pushed ...
- (IBAction)AcceptFriendRequest:(id)sender {
PFObject *SelectedUser = [self.UtentiInAttesa objectAtIndex:[sender tag]];
[SelectedUser setObject:#"Confermato" forKey:#"STATO"];
[SelectedUser saveInBackground];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.2];
[UIView setAnimationBeginsFromCurrentState:YES];
FFScrollView.frame = CGRectMake(FFScrollView.frame.origin.x, (FFScrollView.frame.origin.y - 80.0), FFScrollView.frame.size.width, FFScrollView.frame.size.height);
[UIView setAnimationRepeatAutoreverses:YES];
[UIView commitAnimations];
}
In your button event handler
- (IBAction)myBtnClicked:(id)sender {
// Create new CGRect indicate place where you would scroll to.
// Assume it is called `originalRect`
// Use the following method, it should work
[FFScrollView.scroll scrollRectToVisible:originalRect animated:YES];
}

Change pushViewController animation direction

i read alot about faking the animation of pushViewController, but I'm wondering if there is a way to change the actually animation, because I would like to use the navBar and the BackButton of the navigationController.
Currently I'm using this to animate:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:YES];
[views setContentSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height -40)];
CGRect frame = views.frame;
frame.origin.y = - self.view.bounds.size.height;
[UIView beginAnimations:#"viewSlideUp" context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
views.frame = frame;
[UIView commitAnimations];
}
but I get an overlapping effect, so my view isn't sliding up, the view is sliding away to the top left side.
Has anyone dealed with that problem? Thx for any kinda help!

How can I call uianimation on imageView looks like Circle

I want to create circle uiimageview animation. When uiimage finished at self.left immediately calls again from after uiimageview.right. I want to call animation looks like but my animation was bad. Because when it finished self.left, it started self.right. :( But I want to look like image:
[ ----(end of image)--------- --------(start of image)]
Me. I did it.
[ -----(end of image)---------- ]
When finished end of image, it coming after.
My code looks like:
//for start
[UIView beginAnimations:nil context:nil];
imageView.left = - imageView.width;
// imageView2.left = - imageView.width;
[UIView setAnimationDuration:140.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(moveToLeft:finished:context:)];
[UIView commitAnimations];
-(void)moveToLeft:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
imageView.left = self.right;
imageView2.left = self.right + 3600;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:140.0];
[UIView setAnimationDelegate:self];
imageView.left = -imageView.right;
imageView2.left = -imageView2.right;
// imageView.left = - imageView.width;
[UIView setAnimationDidStopSelector:#selector(moveToLeft:finished:context:)];
[UIView commitAnimations];
// imageView.frame.origin.x = imageView.left - self.right
}
How can i do this. Thanks
Rather than using beginAnimations, it's now recommended to use the block based approach (available on iOS4 and higher).
[UIVIew animateWithDuration:140.0 delay:0.0
options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
animations:^(void) {
imageView.frame = CGRectMake( *Add Final position here* );
}
completion:^(BOOL finished) {}];
The options:UIViewAnimationOptionAutoreverse option will ensure that the animation goes backwards and forwards. The UIViewAnimationOptionRepeat option will keep the animation going.
Inside the block add your animation code to where the view should move. It'll then move back and forwards to that point.

UIWebView and Animation

I am wondering if there was a way to animate the size and position of a UIWebView.
If I do sth like this:
[UIView animateWithDuration:1.0 animations:^{
self.frame = CGRectMake(20.0, 20.0, 80.0, 80.0);
}];
or
[UIView beginAnimations:#"zoomIn" context:nil];
[UIView setAnimationDuration:2.75];
[UIView setAnimationDelegate: self];
self.frame = CGRectMake(20.0, 20.0, 80.0, 80.0);
[UIView commitAnimations];
while there is a grey box doing the animation,
the content of the WebView instantly switches to the new size without animating.
(the scalesPageToFit property is set to YES)
any suggestions on that?
Haven't cracked the instant changing of the text width yet but you can get rid of the grey box by programmatically changing the background of the UIWebView to clearColor. Doesn't work if you do it through Interface Builder, for some reason.

Resources