【发布时间】:2015-07-11 22:17:10
【问题描述】:
我注意到如果我做这样的事情
[self setTitle:@"Follow" forState:UIControlStateNormal];
[self setTitle:@"Following" forState:UIControlStateSelected];
该按钮将以“关注”开始。我按下它,当我松开手指(触摸事件)时,它变为“Following”。那太棒了。但是,当它现在被选中并按下它时,它会在我松开手指之前立即变为“跟随”(在触摸事件中)。我想在松开手指时进行更改(修饰事件)。我该怎么做呢?我将 UIControlStates 用于 UIButton 的标题、图像和标题颜色。
下面是我的事件处理程序:
- (void)followButtonAction:(UIButton *)button
{
button.selected = !button.selected;
}
我是这样设置的:
[self.followButton addTarget:self action:@selector(followButtonAction:) forControlEvents:UIControlEventTouchUpInside];
【问题讨论】:
-
那你为什么同时使用“touch down event”和“touch up event”呢?
-
尝试设置 UIControlStateHighlighted 也..
-
button.selected 在修饰事件中设置。这就是使这种行为变得奇怪的原因。我自己尝试了 UIControlStateHighlighted 状态并与 UIControlStateSelected 结合使用。没有运气。
-
似乎 button.state 和 button.selected 不会同时改变。无论 button.selected 何时更改。 button.state 在 touch up 期间设置为 UIControlStateSelected,在 touch down 期间设置为 UIControlStateNormal。
标签: ios objective-c uibutton uicontrolstate