我如何才能使UIButton
从视图中慢慢消失?我正在寻找的动画会使按钮看起来像它的宽度向下。我应该使用Core Animation
吗?我对iPhone开发很陌生,但这似乎应该是可行的
答案 0 :(得分:1)
使用UiView并将按钮放在上面...然后将动画添加到Uiview ...你想要什么
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];
不要忘记导入QuartzCore / QuartzCore框架
答案 1 :(得分:1)
似乎只是想通过使用UIView的类方法animateWithDuration:animations:
[UIView animateWithDuration:<some duration> animations:^{
myButton.center = (CGPoint){myButton.center.x, CGRectGetMaxY(self.view.frame) + (CGRectGetHeight(myButton.bounds)/2.0)};
}];
CoreAnimation对于这个简单的操作来说太过分了。