Tag: touchesbegan

你怎么知道触摸什么对象?

我知道这是一个非常常见的问题,但是每个网站上的所有答案都不起作用! 如果你仍然不知道我的意思,那么也许这行代码将帮助你理解。 – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint location = [touch locationInView:self.view]; if (touch.view == nextbutton) [self performSelector:@selector(next)]; if (touch.view == prevbutton) [self performSelector:@selector(previous)]; if (touch.view == moreoptionsbutton) [self performSelector:@selector(moresettings)]; } nextbutton, prevbutton, and more optionsbutton当你触摸nextbutton, prevbutton, and more optionsbutton ( UIImageViews ,它什么也不做。 我也尝试使用isEqual:而不是== ,但是还没有解决。 有什么build议么?

伸展的UIBezierPath线?

我想用我的手指画出一条直线,根据我离原点的距离来自动resize。 所以如果我在中间触摸屏幕并且滑动我的手指,当我的手指在屏幕上移动时,一条线似乎“伸展”并围绕orgin点旋转。 当我抬起我的手指。 目的地点应最终确定并创build一条线。 我可以将手指拖过屏幕,然后在屏幕上“绘制”,但这不是我想要做的。 我认为UIBeizerPath moveToPoint会帮助,但它只是弄乱了事情。 我究竟做错了什么? – (id)initWithFrame:(CGRect)frame { //default line properties myPath=[[UIBezierPath alloc]init]; myPath.lineCapStyle=kCGLineCapRound; myPath.miterLimit=0; myPath.lineWidth=lineWidth; brushPattern=[UIColor blackColor]; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint curPoint = [[touches anyObject] locationInView:self]; lastPoint = curPoint; [myPath moveToPoint:lastPoint]; [pathArray addObject:myPath]; [self setNeedsDisplay]; } -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ CGPoint curPoint = [[touches anyObject] locationInView:self]; myPath.lineWidth=lineWidth; brushPattern=[UIColor […]

touchesBegan不在UIView子类中调用

我试图模仿GLPaint应用程序,我有一个TDPaintingView具有方法-(void)touchesBegan…以及touchesMoved , touchesEnded ,并touchesCanceled 。 但是,我没有看到他们中的任何一个火。 我有一个TDAppDelegate连接到IB中的Window和IB中的TDPaintingView 。 我的TDPaintingView的initWithCoder方法肯定会触发,所以我知道它正在被初始化。 此外,我可以从TDPaintingView的上下文中logging对象TDPaintingView ,这是肯定存在的。 当我在IB中改变视图的方式(比如使bg红色)在模拟器上反映出来。 但是,我的观点并没有得到触动,而且这让我疯狂! 我在-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event上设置了一个断点-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event ,它永远不会停止,无论我在屏幕上的哪个位置触摸。 我的TDPaintingView没有子视图,它明确定义了触摸操作的方法。 我哪里错了?

Touchesbegan没有检测到正在触摸的东西

我正在使用NSTimer构build一个旋转横幅,从5个不同的图像中跟踪当前图像的animation。 我有一个touchesBegan设置,以保持处理横幅上的触摸事件,如果有人点击它。 我的概念validation工作,但移动到另一个项目,它打破了。 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch = [[event allTouches] anyObject]; if ([touch view] == myImageView){ [self getImage]; NSLog(@"%@", currentImage); } } 现在,当我把断点放到我的项目中时,它抓住了触摸就好,但是当它到达if([touch view] == myImageView)时,它不检测到图像视图正在被触摸。

触动开始,触动已结束,触动移动UIView移动

我需要拖动我的UIView对象。 我使用这个代码,但它不工作 float oldX, oldY; BOOL dragging; – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint touchLocation = [touch locationInView:self]; if ([[touch.view class] isSubclassOfClass:[UILabel class]]) { UILabel *label = (UILabel *)touch.view; if (CGRectContainsPoint(label.frame, touchLocation)) { dragging = YES; oldX = touchLocation.x; oldY = touchLocation.y; } } } – (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent […]