繁体   English   中英

在自定义UIView上对UIButton进行动画处理

[英]Animating a UIButton on a custom UIView

我有一个自定义视图,上面有一个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)];
}];
}

怎么了

以此替换您的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.

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