使用动画修改UIButton宽度

时间:2011-08-11 12:37:39

标签: iphone xcode animation uibutton width

这是我的代码,

-(IBAction)casser{
     oeuf1.contentMode       =   UIViewContentModeScaleAspectFit;
    [UIView animateWithDuration:1.0 animations:^{ 
         CGRect newRect      =   oeuf1.frame;
         newRect.size.width *=   5;
         oeuf1.frame         =   newRect;
         [oeuf1 release];
    }];
}

“oeuf1”是一个UIButton 当我触摸按钮时,我想将其宽度乘以5,但是当我这样做时,按钮向右移动,其宽度不会改变。我该如何解决这个问题?

3 个答案:

答案 0 :(得分:0)

经过测试的代码100%正常工作

使用指定的

连接每个方法
-(IBAction)expand{//touch down


    NSLog(@"expand");

    [UIView transitionWithView:but duration:0.0 options:UIViewAnimationOptionTransitionNone animations:^(void) {


        CGRect newRect = but.frame;

        CGPoint ce= but.center;
        newRect.size.width *= 5;

        but.frame = newRect;    

        but.center=ce;



    } completion:^(BOOL finished) {



    }];


}

 -(IBAction)shrink{//touch up inside
    NSLog(@"shrink");


    [UIView transitionWithView:but duration:0.0 options:UIViewAnimationOptionTransitionNone animations:^(void) {


        CGRect newRect = but.frame;

        CGPoint ce= but.center;
        newRect.size.width /= 5;

        but.frame = newRect;    

        but.center=ce;



    } completion:^(BOOL finished) {



    }];


}

答案 1 :(得分:0)

工作答案:

删除[oeuf1 release];

答案 2 :(得分:-1)

为什么不使用

[oeuf1 setFrame:CGRectMake(oeuf1.frame.origin.x, oeuf1.frame.origin.y, oeuf1.frame.size.width*2, oeuf1.frame.size.height)];