簡體   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