Reputation: 1175
How would I go about making this UIButton
slowly disappear from the view? The animation I'm looking for would make the button look like its widthrawing downward. Should I use Core Animation
? I'm rather new to iPhone development, but this seems like something that should be doable
Upvotes: 0
Views: 531
Reputation: 3208
Seems like you just want to animate the changing of the frame (or precisely, the center position) simply by using UIView's class method animateWithDuration:animations:
[UIView animateWithDuration:<some duration> animations:^{
myButton.center = (CGPoint){myButton.center.x, CGRectGetMaxY(self.view.frame) + (CGRectGetHeight(myButton.bounds)/2.0)};
}];
CoreAnimation would be overkill for this simple operation.
Upvotes: 1
Reputation: 6570
Use UiView and put the button on it... then add animation to the Uiview...What you want
UIView *upwardView=[[UIView alloc]init];
upwardView.backgroundColor=[UIColor blueColor];
[upwardView setFrame:CGRectMake(0, 10, 320, 200)];
UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:@"Click me" forState:UIControlStateNormal];
btn.frame=CGRectMake(10, 20, 120, 40);
[upwardView addSubview:btn];
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFade];
[animation setDuration:.50];
[animation setDelegate:self];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
CALayer *layer = [upwardView layer];
[layer addAnimation:animation forKey:nil];
[self.view.window addSubview:upwardView];
don't forget to import QuartzCore/QuartzCore framework
Upvotes: 1