2 tane görüşüme sahibim, ama 1 görüntüyü (neredeyse) daha büyük yapmak istiyorum. Eğer tapGesture'ı v1'e yerleştirirsem, hafifçe vurma hareketi büyük isabet alanıyla çalışır, ancak tapGesture'u v2'ye yerleştirirsem işe yaramıyor (aslında tapGesture'ı tanımaz, orijinal sınırlar içinde olmasa bile) TestView1 yönteminden geçtiğim ve çerçevede yer aldığım noktalara rağmen.hitTest: WithEvent ve Subviews
#import "ViewController.h"
@interface TestView1 : UIView
@end
@implementation TestView1
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
CGFloat radius = 100.0;
CGRect frame = CGRectMake(0, 0,
self.frame.size.width + radius,
self.frame.size.height + radius);
if (CGRectContainsPoint(frame, point)) {
return self;
}
return nil;
}
@end
@interface TestView2 : UIView
@end
@implementation TestView2
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
CGFloat radius = 100.0;
CGRect frame = CGRectMake(0, 0,
self.frame.size.width + radius,
self.frame.size.height + radius);
if (CGRectContainsPoint(frame, point)) {
return self;
}
return nil;
}
@end
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
TestView1 *v1 = [[TestView1 alloc] initWithFrame:CGRectMake(50.f, 50.f, 100.f, 100.f)];
[self.view addSubview:v1];
TestView2 *v2 = [[TestView2 alloc] initWithFrame:CGRectMake(0.f, 0.f, 100.f, 100.f)];
v2.backgroundColor = UIColor.yellowColor;
[v1 addSubview:v2];
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(panGesture:)];
[v2 addGestureRecognizer:gesture];
}
- (void) panGesture:(UIPanGestureRecognizer *)recognizer
{
NSLog(@"tap");
}
@end
Sam'in kodu, dokunmatik alanı aşağı ve sağa doğru genişletir. CGFloat dolgu = 50 hakkında ne dersiniz? CGRect frame = CGRectMake (tuş takımı, -padding, self.frame.size.width + padding, self.frame.size.height + dolgu); – Nuthatch
@Nuthatch Peki, orijinal kod Andy tarafından da yapılacak. Ama iyi bir nokta – LoPoBo