0
TL的用戶交互; DR如何禁用一個UIView的面具
我只是想知道是否有任何方法來禁用只爲視圖的遮蔽部分用戶交互。
我這裏還有場景:
我有兩個觀點觀,視圖B,都是平等寬度和等高的。
視圖B是上視圖A的頂部
我在底部施加在視圖B掩模(CAShapeLayer)看的視圖的內容(兩個按鈕)甲
由於視圖B有一個面具,我只能看到觀的內容,但我ñ不能與它交互。
任何幫助,將不勝感激。謝謝。
TL的用戶交互; DR如何禁用一個UIView的面具
我只是想知道是否有任何方法來禁用只爲視圖的遮蔽部分用戶交互。
我這裏還有場景:
我有兩個觀點觀,視圖B,都是平等寬度和等高的。
視圖B是上視圖A的頂部
我在底部施加在視圖B掩模(CAShapeLayer)看的視圖的內容(兩個按鈕)甲
由於視圖B有一個面具,我只能看到觀的內容,但我ñ不能與它交互。
任何幫助,將不勝感激。謝謝。
讓你查看B中色澤鮮明,在您的視圖控制器或視圖的子類嘗試在下面的代碼項目UIView+ColorOfPoint和用戶UIView+ColorOfPoint.h
和UIView+ColorOfPoint.m
文件.. Sample Project我使用下面的代碼在UIView子類(定製類) 。
#pragma mark - Hit testing
- (BOOL)isAlphaVisibleAtPoint:(CGPoint)point forImage:(UIView *)view
{
// Correct point to take into account that the image does not have to be the same size
// as the button. See https://github.com/ole/OBShapedButton/issues/1
CGSize iSize = view.bounds.size;
CGSize bSize = self.bounds.size;
point.x *= (bSize.width != 0) ? (iSize.width/bSize.width) : 1;
point.y *= (bSize.height != 0) ? (iSize.height/bSize.height) : 1;
UIColor *pixelColor = [view colorOfPoint:point];
CGFloat alpha = 0.0;
if ([pixelColor respondsToSelector:@selector(getRed:green:blue:alpha:)])
{
// available from iOS 5.0
[pixelColor getRed:NULL green:NULL blue:NULL alpha:&alpha];
}
else
{
// for iOS < 5.0
// In iOS 6.1 this code is not working in release mode, it works only in debug
// CGColorGetAlpha always return 0.
CGColorRef cgPixelColor = [pixelColor CGColor];
alpha = CGColorGetAlpha(cgPixelColor);
}
return alpha >= kAlphaVisibleThreshold;
}
// UIView uses this method in hitTest:withEvent: to determine which subview should receive a touch event.
// If pointInside:withEvent: returns YES, then the subview’s hierarchy is traversed; otherwise, its branch
// of the view hierarchy is ignored.
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
// Return NO if even super returns NO (i.e., if point lies outside our bounds)
BOOL superResult = [super pointInside:point withEvent:event];
if (!superResult) {
return superResult;
}
// Don't check again if we just queried the same point
// (because pointInside:withEvent: gets often called multiple times)
if (CGPointEqualToPoint(point, self.previousTouchPoint)) {
return self.previousTouchHitTestResponse;
} else {
self.previousTouchPoint = point;
}
BOOL response = NO;
if (self == nil) {
response = YES;
}
else if (self!= nil) {
response = [self isAlphaVisibleAtPoint:point forImage:self];
}
else {
if ([self isAlphaVisibleAtPoint:point forImage:self]) {
response = YES;
} else {
response = [self isAlphaVisibleAtPoint:point forImage:self];
}
}
self.previousTouchHitTestResponse = response;
return response;
}
- (void)resetHitTestCache
{
self.previousTouchPoint = CGPointMake(CGFLOAT_MIN, CGFLOAT_MIN);
self.previousTouchHitTestResponse = NO;
}
我不知道,但我在這裏想我的答案:http://stackoverflow.com/a/37658235/6285303相關 – sanman