我正在使用UIScrollView我得到了一些UIButtons,认识到我按下了上面的按钮,我创建了一个UIScrollView的子类,其中重写了方法
- (BOOL) touchesShouldCancelInContentView (UIView *) view
但是只有当触摸是一段旅程时才进入该方法,当我不再按屏幕时,永远不会进入。
我创建的UIScrollView:
`
CGSize containerSize = CGSizeMake(320.0f, 480.0f);
CGSize containerSize2 = CGSizeMake(640.0f, 960.0f);
self.scrollView = [[UIScrollViewWithButtons alloc] initWithFrame:(CGRect){.origin=CGPointMake(0.0f, 0.0f), .size=containerSize}];
[self.scrollView setMinimumZoomScale:0.5f];
[self.scrollView setMaximumZoomScale:1.0f];
[self.scrollView setZoomScale:0.5f];
[self.scrollView setDelegate:self];
self.scrollView.bounces = NO;
self.scrollView.bouncesZoom = NO;
self.scrollView.delaysContentTouches = NO;
self.scrollView.userInteractionEnabled = YES;
[self.scrollView setContentInset:UIEdgeInsetsZero];
[self.view addSubview:self.scrollView];
self.containerView = [[UIView alloc] initWithFrame:(CGRect){.origin=CGPointMake(0.0f, 0.0f), .size=containerSize2}];
self.containerView.userInteractionEnabled = YES;
[self.scrollView addSubview:self.containerView];
[self.scrollView setClipsToBounds:NO];
//instanciar uimageview
fondo = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 640, 960)];
[self.containerView addSubview:fondo];
[fondo setImage:[UIImage imageNamed:@"Grande.png"]];
self.scrollView.contentSize = containerSize2;
和按钮添加
imagen = [UIButton buttonWithType:UIButtonTypeCustom];
[imagen addTarget:self action:@selector(pulsadoIzq) forControlEvents:UIControlEventTouchUpInside];
[imagen setTitle:@"" forState:UIControlStateNormal];
[imagen setFrame:CGRectMake(xUser, yUser, 50.0f, 50.0f)];
[imagen setImage:[UIImage imageNamed:@"boton.png"] forState:UIControlStateNormal];
[self.containerView addSubview:fichaUserIzq];
imagen.center = CGPointMake(xUser, yUser);`enter code here`
我需要将屏幕上的水龙头捕捉到按钮上 我该怎么做?
我也想知道,因为如果我实现了这段代码:
img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"img.png"]];
UIPanGestureRecognizer *panRecg = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(imgDragged:)];
img.userInteractionEnabled = YES;
[img addGestureRecognizer:panRecg];
img.center = CGPointMake(160, 436);
[self.scrollView addSubview:img];
当我点击图像时没有任何反应,没有进入方法,只有当我按下并拖动时才会进入。我也希望在按下此图像时捕获,因此我只在移动时捕获。
答案 0 :(得分:0)
我解决了这个问题,我实现了这个方法:
-(void)singleTapGestureCaptured:(UITapGestureRecognizer*)gesture{
CGPoint touchPoint = [gesture locationInView:self.scrollView];
if ((touchPoint.x > 88)&&(touchPoint.x < 226)&&(touchPoint.y > 172)&&(touchPoint.y < 319)) {
if (rodando) {
[self pararAnimacionDado];
}
}
}
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
[scrollView addGestureRecognizer:singleTap];