[英]Animating a UIButton on a custom UIView
I have a custom view on which I have a UIButton
. 我有一个自定义视图,上面有一个UIButton
。 I am trying to do a simple animation in which the button should get half in size within a second of pressing the button. 我正在尝试做一个简单的动画,在该动画中,按钮在按下按钮后的一秒钟内应该变小一半。
However the problem is that button is not animating I have checked the action method and it is being called but the buttons are not being animated. 但是问题是按钮没有设置动画,我已经检查了动作方法并且正在调用它,但是按钮没有设置动画。
-(instancetype)initWithFrame:(CGRect)frame
{
if (self=[super initWithFrame:frame]) {
//Loading From Nib
NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"SelectionMenu" owner:nil options:nil];
[self addSubview:views[0]];
}
return self;
}
- (IBAction)firstBtn:(id)sender {
//Disabling the other two buttons
self.upperBtn2.backgroundColor = [UIColor grayColor];
self.upperBtn3.backgroundColor = [UIColor grayColor];
[self.slider setHidden:NO];
[self.slider.layer setZPosition:9.0];
[self startAnimation];
self.upperBtn2.userInteractionEnabled = NO;
self.upperBtn3.userInteractionEnabled = NO;
}
-(void)startAnimation
{
[UIView animateWithDuration:1.0 animations:^{
[self.upperBtn1 setFrame:CGRectMake(10, 20, 100, 100)];
}];
}
What is wrong here. 怎么了
Replace your startAnimation with this, 以此替换您的startAnimation,
- (void)startAnimation
{
[UIView animateWithDuration:1.0 animations:^{
self.upperBtn1.transform = CGAffineTransformMakeScale(0.5, 0.5);
}];
}
[UIView animateWithDuration:1.0
delay:1.0
options:UIViewAnimationCurveEaseInOut
animations:^ {
self.btn.frame = CGRectMake(self.btn.frame.origin.x,self.btn.frame.origin.y,50,50);
}completion:^(BOOL finished) {
}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.