我将如何让它UIButton
慢慢从视图中消失?我正在寻找的动画会使按钮看起来像它的宽度向下。我应该使用Core Animation
吗?我对 iPhone 开发相当陌生,但这似乎应该是可行的
问问题
520 次
2 回答
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 框架
于 2013-08-12T04:19:12.857 回答
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 将是多余的。
于 2013-08-12T04:27:16.693 回答