在自定义UIView上设置UIButton的动画

时间:2014-11-13 13:00:04

标签: ios objective-c uiview uibutton uiviewanimation

我有一个自定义视图,我有一个UIButton。我正在尝试做一个简单的动画,按钮在按下按钮的一秒钟内按钮尺寸减半。

然而问题是按钮没有动画我已经检查了动作方法并且正在调用它但按钮没有动画。

-(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)];
}];
}

这里有什么问题。

2 个答案:

答案 0 :(得分:0)

用这个替换你的startAnimation,

- (void)startAnimation
{
    [UIView animateWithDuration:1.0 animations:^{
        self.upperBtn1.transform = CGAffineTransformMakeScale(0.5, 0.5);
    }];
}

答案 1 :(得分:0)

 [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) {

                 }];