如何在触摸时禁用UIButton图像的颠倒翻转? [英] How to disable upside-down fliping of UIButton image when it's touched?

查看:144
本文介绍了如何在触摸时禁用UIButton图像的颠倒翻转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为UIButton为UIControlStateNormal设置了一个图像,如果我按下此按钮,图像会被遮挡并翻转到我持有它的时间。

I seted an image for UIButton for "UIControlStateNormal" and if I press this button the image is shadowed and flips upside down for the time that i hold it.

阴影是可以的,但如果我不想设置状态为UIControlStateHighlighted的自定义图像,如何禁用滑动?
感谢您的帮助

Shadowing is ok, but how can I disable the fliping, if I dont want to set a custom image fo state "UIControlStateHighlighted" ? Thanks for help

制作按钮的代码是:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.tag=i;
        [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        button.frame = CGRectMake(xakt, yakt, a, b);

然后我用 - (void)setImage设置按钮图像: (UIImage *)image forState:(UIControlState)state function。
我包括2张图片,第一张是正常状态,第二张是处于按下状态

and after that I set the button image with - (void)setImage:(UIImage *)image forState:(UIControlState)state function. I included 2 images, first in normal state, the second in pressed state

推荐答案

我对上述这种行为的观察(单击按钮时图像反转)仅限于以下情况:

My observation of this behavior described above (image on button inverts when clicked) is limited to the following situations:


  1. 按钮的图像使用
    设置 - (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state 状态为 UIControlStateNormal

这种情况可能不是必需的,但是 UIImage 的imageOrientation UIImageOrientationDown

This condition is likely not required but the imageOrientation of the UIImage is UIImageOrientationDown.

指定其余两个控制状态的背景图像可以解决问题。

Specifying the background image for two remaining control states should fix the problem.

UIButton *button = ...
UIImage *image = ...
[button setBackgroundImage:image forState:UIControlStateNormal];
// Specify same image for selected / highlighted states
[button setBackgroundImage:image forState:UIControlStateSelected];
[button setBackgroundImage:image forState:UIControlStateHighlighted];

请注意:

[button setBackgroundImage:image
                  forState:UIControlStateNormal |
                           UIControlStateSelected |
                           UIControlStateHighlighted];

不起作用。

这篇关于如何在触摸时禁用UIButton图像的颠倒翻转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆