我的应用主视图底部有几个 UIButton.当用户点击它们时,这些按钮间歇性地不会突出显示,但它们的目标方法总是被调用.我发现它是控制中心的手势识别器妨碍了 UIButton 的突出显示.如果我将包含视图向上移动到屏幕中间,一切都会按设计运行.
I have a few UIButtons at the bottom of my app's main view. These buttons intermittently don't highlight when a user taps them but their target methods always get called. I've discovered it's Control Center's gesture recognizer getting in the way of UIButton's highlighting. If I move the containing view up toward the middle of the screen everything functions as designed.
这里报告了问题https://devforums.apple.com/message/865922
作为一种解决方法,我尝试使用目标方法手动设置突出显示的状态.这似乎与允许 UIButton 正常突出显示的效果相同.
As a workaround I've tried setting the highlighted state by hand with the target method. This seems to have the same effect of allowing the UIButton to highlight normally.
任何想法如何在不重新设计这些控件以显示在应用程序的其他位置的情况下解决此问题?
Any ideas how to work around this without redesigning these controls to appear elsewhere in the app?
也许我使用标准视图并手动添加触摸交互的所有方法?我该怎么做?它甚至值得探索吗?
Perhaps I use a standard view and add all the methods for touch interaction by hand? How would I do that? Is it even worth exploring?
我找到了一个非常简单的解决方法.使用 .highlighted = YES 和 .selected = YES 等标准属性似乎在该底部范围内不起作用.在调用 final 方法之前,我没有设置高亮状态,而是将按钮的背景图像设置为高亮状态,并有一个无法察觉的延迟.
I've found a pretty simple workaround for this. Using standard properties like .highlighted = YES and .selected = YES doesn't seem to work within that bottom band. Instead of setting the highlighted state, I just set the background image of the button to the highlighted state with an unperceived delay BEFORE we call the final method.
[self.stopRecordingButton setImage:[UIImage imageNamed:@"stopRecordingButton"] forState:UIControlStateNormal];
[self.stopRecordingButton setImage:[UIImage imageNamed:@"stopRecordingButton-highlighted"] forState:UIControlStateHighlighted];
[self.stopRecordingButton addTarget:self action:@selector(stopRecordingDelay) forControlEvents:UIControlEventTouchUpInside];
-(void)stopRecordingDelay
{
[self.stopRecordingButton setImage:[UIImage imageNamed:@"stopRecordingButton-highlighted"] forState:UIControlStateNormal];
[self performSelector:@selector(stopRecording) withObject:nil afterDelay:0.025f];
}
- (void)stopRecording
{
[self.stopRecordingButton setImage:[UIImage imageNamed:@"stopRecordingButton"] forState:UIControlStateNormal];
//Do real stuff
}
这篇关于屏幕底部的 UIButton 仅间歇性突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!