【问题标题】:Animating a UIButton on a custom UIView在自定义 UIView 上为 UIButton 设置动画
【发布时间】:2014-11-13 13:00:04
【问题描述】:

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

这里有什么问题。

【问题讨论】:

  • firstBtn 是否调用 touchUpInside:?如果是这样,请将其重置为 touchDown

标签: ios objective-c uiview uibutton uiviewanimation


【解决方案1】:
 [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) {

                 }];

【讨论】:

    【解决方案2】:

    用这个替换你的 startAnimation,

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多