0
-(IBAction)actionButtonPressed:(id)sender {
//Write the code to show the buttons etc like play
[UIView animateWithDuration:0.5
                      delay:0.0
                    options:UIViewAnimationOptionAllowAnimatedContent
                 animations:^{
                     [self.actionBtn0 setFrame:CGRectMake(25, 25, 100, 100)];
                     [self.actionBtn1 setFrame:CGRectMake(40, 40, 70, 70)];
                     [self.actionBtn2 setFrame:CGRectMake(0, 0, 150, 150)];

                 } completion:^(BOOL finished) {
                     [UIView animateWithDuration:2.0
                                           delay:0.0
                                         options:UIViewAnimationOptionCurveLinear
                                      animations:^{
                                          playBtn.alpha = 1.0;
                                      }
                                      completion:NULL];
                 }];

}

我有一个按钮,当应用程序加载时它很大并且位于屏幕中央。但是,当它被按下时,我希望它缩小尺寸并移动到屏幕的右上角。实际上有 3 个按钮,但它们都共享上面显示的相同 IBAction。

我遇到的问题是,根据按下按钮的时间,按钮的图像会变成我没有指定的随机怪异形状。图像应该是完美的圆形,但它们往往会被重新绘制成椭圆形。知道如何阻止这种情况吗?

按下按钮之前按钮的原始尺寸如下。

actionBtn0 = [[UIButton alloc] initWithFrame:CGRectMake(60, 185, 200, 200)];
[actionBtn0 setImage:[UIImage imageNamed:@"bigLineRing.png"] 
forState:UIControlStateNormal];
[actionBtn0 addTarget:self action:@selector(actionButtonPressed:) 
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:actionBtn0];
[self.view bringSubviewToFront:actionBtn0];

actionBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(90, 215, 140, 140)];
[actionBtn1 setImage:[UIImage imageNamed:@"smallLineRing.png"] 
forState:UIControlStateNormal];
[actionBtn1 addTarget:self action:@selector(actionButtonPressed:) 
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:actionBtn1];
[self.view bringSubviewToFront:actionBtn1];

actionBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(10, 135, 300, 300)];
[actionBtn2 setImage:[UIImage imageNamed:@"theEye.png"] forState:UIControlStateNormal];
[actionBtn2 addTarget:self action:@selector(actionButtonPressed:) 
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:actionBtn2];
[self.view bringSubviewToFront:actionBtn2];
4

1 回答 1

0

而不是使用 UIButton 的这种创建;

actionBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(90, 215, 140, 140)];
[actionBtn1 setImage:[UIImage imageNamed:@"smallLineRing.png"] forState:UIControlStateNormal];

尝试使用这个:

actionBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
actionBtn1.frame = CGRectMake(90, 215, 140, 140);
[actionBtn1 setImage:[UIImage imageNamed:@"smallLineRing.png"] forState:UIControlStateNormal];
于 2013-09-17T14:18:31.680 回答