Objective c 按下此按钮时,形状会发生变化
我有一个按钮,当应用程序加载它是大的,在屏幕的中心。然而,当它被按下时,我希望它缩小到屏幕的右上角。实际上有3个按钮,但它们都共享上面显示的相同iAction 我遇到的问题是,根据按下按钮的时间,按钮的图像会变形为我没有指定的随机奇怪形状。图像应该是完美的圆形,但它们倾向于以椭圆方式重新绘制。你知道怎么阻止吗 按下按钮前按钮的原始尺寸如下所示Objective c 按下此按钮时,形状会发生变化,objective-c,animation,uibutton,image-size,Objective C,Animation,Uibutton,Image Size,我有一个按钮,当应用程序加载它是大的,在屏幕的中心。然而,当它被按下时,我希望它缩小到屏幕的右上角。实际上有3个按钮,但它们都共享上面显示的相同iAction 我遇到的问题是,根据按下按钮的时间,按钮的图像会变形为我没有指定的随机奇怪形状。图像应该是完美的圆形,但它们倾向于以椭圆方式重新绘制。你知道怎么阻止吗 按下按钮前按钮的原始尺寸如下所示 -(IBAction)actionButtonPressed:(id)sender { //Write the code to show the butt
-(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];
}];
}
而不是使用这个创建UIButton
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];
尝试使用以下方法:
actionBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(90, 215, 140, 140)];
[actionBtn1 setImage:[UIImage imageNamed:@"smallLineRing.png"] forState:UIControlStateNormal];
我以前也遇到过同样的问题,如果您忘记更改任何自定义按钮类型,就会发生这种情况。如果在UIButton中使用image,请不要将Round Rect Button用作类型。
actionBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
actionBtn1.frame = CGRectMake(90, 215, 140, 140);
[actionBtn1 setImage:[UIImage imageNamed:@"smallLineRing.png"] forState:UIControlStateNormal];