[英]subview user interaction disabled on UIViewController on iOS 7
[英]iOS 7.0 User interaction disabled for controls inside UITableView backgroundView
我將自定義視圖設置為UITableview的背景視圖。當tableview為空時,它用於執行某些操作。
我在視圖上有一些按鈕,每個按鈕都有一個動作
對於iOS <7,在背景視圖內的按鈕上正確調用動作但是對於iOS> 7,在backgroundView中的按鈕上設置的動作不會被調用。這似乎在backgroundView上禁用了交互
這是iOS 7的問題嗎。其他人面臨同樣的問題嗎?
在背景視圖前面有一個UITableViewWrapperView
視圖攔截交互。 你能不能只使用表的tableHeaderView
屬性?
首先,這是向tableView背景視圖添加可觸摸項的不好方法。 其次,我不確定我的修復是否適用於您的情況。
嘗試在BackgroundView類中實現以下方法:
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event
{
UIView* hitView = [super hitTest:point withEvent:event];
if (hitView != nil)
{
[self.superview bringSubviewToFront:self];
}
return hitView;
}
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event
{
CGRect rect = self.bounds;
BOOL isInside = CGRectContainsPoint(rect, point);
if(!isInside)
{
for (UIView *view in self.subviews)
{
isInside = CGRectContainsPoint(view.frame, point);
if(isInside)
break;
}
}
return isInside;
}
通過覆蓋這些方法,您將使backgroundView的所有子視圖以及backgroundView本身都具有觸摸敏感性。
干杯!
更新:
對不起,這不行。 BackgroundView位於視圖后面,單元格本身,因此不會接觸到觸摸。
正如我的評論中所述,這是iOS7中的一個已知問題,請參閱雷達( http://openradar.appspot.com/14707569 )。
但我的解決方案或解決方法是在表的頂部實現一個“代理”視圖,該視圖提供了一個協議,用於將hitTest轉發給實現該協議的代理。
EventFixBackrgoundView.h
@protocol EventFixBackrgoundViewDelegate <NSObject>
- (UIView *)eventFixHitTest:(CGPoint)point withEvent:(UIEvent *)event;
@end
@interface EventFixBackrgoundView:UIView
@property (nonatomic, weak) id <EventFixBackrgoundViewDelegate> delegate;
@end
EventFixBackrgoundView.m
#import "EventFixBackrgoundView.h"
@implementation EventFixBackrgoundView
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if (self.delegate && [self.delegate respondsToSelector:@selector(eventFixHitTest:withEvent:)])
{
return [self.delegate eventFixHitTest:point withEvent:event];
}
return [super hitTest:point withEvent:event];
}
@end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.