简体   繁体   中英

Animating a UIButton on a custom UIView

I have a custom view on which I have a 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,

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

                 }];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM