Search Results

Search found 87 results on 4 pages for 'touchesmoved'.

Page 1/4 | 1 2 3 4  | Next Page >

  • iPhone multitouch - Some touches dispatch touchesBegan: but not touchesMoved:

    - by zkarcher
    I'm developing a multitouch application. One touch is expected to move, and I need to track its position. For all other touches, I need to track their beginnings and endings, but their movement is less critical. Sometimes, when 3 or more touches are active, my UIView does not receive touchesMoved: events for the moving touch. This problem is intermittent, and can always be reproduced after a few attempts: Touch the screen with 2 fingers. Touch the screen with another finger, and move this finger around. The moving finger always dispatches touchesBegan: and touchesEnded:, but sometimes does not dispatch any touchesMoved: events. Whenever the moving touch does not dispatch touchesMoved: events, I can force it to dispatch touchesMoved: if I move one of the other touches. This seems to "force" every touch to recheck its position, and I successfully receive a touchesMoved: event. However, this is clumsy. This bug is reproducible on both the iPhone 2G and 3GS models. My question is: How do I ensure that my moving touch dispatches touchesMoved: events? Does anyone have any experience with this issue? I've spent few fruitless days searching the web for answers. I found a post describing how to sync touch events with the VBL: http://www.71squared.com/2009/04/maingameloop-changes/ . However, this has not solved the problem. I really don't know how to proceed. Any help is appreciated!

    Read the article

  • Increase frequency calls of touchesMoved

    - by Erika
    Hi Everyone, Is there a way to increase the frequency calls of touchesMoved than the default? I need more calls of it to draw a smooth circle. It gets called not too frequent by default and so I get an edgy circle. Is there a way to tweek the frequency of touchesMoved calls? Thanks

    Read the article

  • touchesMoved QuartzDemo application

    - by BittenApple
    I am modifying the QuartzDemo application to include swipe detection while UIView is active (a PDF page being displayed in it via Quartz). This will not work, the event never gets to the QuartzView.m because it sits under scrollview? touchesBegan works fine and I can use single tap. How can I go about with catching touchesMoved while PDF page is being displayed? I need a simple example with code that does nothing on touchesMoved, I'll build up on that later. Please keep in mind that I still want to use the UIScrollview as it is and show PDF content based on selection in that scrollview.

    Read the article

  • UIScrollView without paging but with touchesmoved

    - by BittenApple
    I have a UIScrollView that I use to display PDF pages in. I don't want to use paging (yet). I want to display content based on touchesmoved event (so after horizontal swipe). This works (sort of), but instead of catching a single swipe and showing 1 page, the swipe seems to gets broken into 100s of pieces and 1 swipe acts as if you're moving a slider! I have no clue what am I doing wrong. Here's the experimental "display next page" code which works on single taps: - (void)nacrtajNovuStranicu:(CGContextRef)myContext { CGContextTranslateCTM(myContext, 0.0, self.bounds.size.height); CGContextScaleCTM(myContext, 1.0, -1.0); CGContextSetRGBFillColor(myContext, 255, 255, 255, 1); CGContextFillRect(myContext, CGRectMake(0, 0, 320, 412)); size_t brojStranica = CGPDFDocumentGetNumberOfPages(pdfFajl); if(pageNumber < brojStranica){ pageNumber ++; } else{ // kraj PDF fajla, ne listaj dalje. } CGPDFPageRef page = CGPDFDocumentGetPage(pdfFajl, pageNumber); CGContextSaveGState(myContext); CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, self.bounds, 0, true); CGContextConcatCTM(myContext, pdfTransform); CGContextDrawPDFPage(myContext, page); CGContextRestoreGState(myContext); //osvjezi displej [self setNeedsDisplay]; } Here's the swiping code: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; UITouch *touch = [touches anyObject]; gestureStartPoint = [touch locationInView:self]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint currentPosition = [touch locationInView:self]; CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x); CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y); if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) { [self nacrtajNovuStranicu:(CGContextRef)UIGraphicsGetCurrentContext()]; } } The code sits in UIView which displays the PDF content, perhaps I should place it into UIScrollView or is the "display next page" code wrong?

    Read the article

  • Alternative of touchesMoved in Unity3D

    - by Arman
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint location = [touch locationInView:touch.view]; CGPoint xLocation = CGPointMake(location.x,racquet_yellow.center.y); racquet_yellow.center = xLocation; } The above event move recquet_yellow(UIImageView) with mouse pointer, or when I move thumb on iPhone screen, I have 3D Object in Unity3D how can I move my object like recquet_yellow. Kindly guide me.

    Read the article

  • get rotation direction of UIView on touchesMoved

    - by mlecho
    this may sound funny, but i spent hours trying to recreate a knob with a realistic rotation using UIView and some trig. I achieved the goal, but now i can not figure out how to know if the knob is rotating left or right. The most pertinent part of the math is here: - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint pt = [touch locationInView:self]; float dx = pt.x - iv.center.x; float dy = pt.y - iv.center.y; float ang = atan2(dy,dx); //do the rotation if (deltaAngle == 0.0) { deltaAngle = ang; initialTransform = iv.transform; }else { float angleDif = deltaAngle - ang; CGAffineTransform newTrans = CGAffineTransformRotate(initialTransform, -angleDif); iv.transform = newTrans; currentValue = [self goodDegrees:radiansToDegrees(angleDif)]; } } ideally, i could leverage a numeric value to tell me if the rotation is positive or negative.

    Read the article

  • iphone sdk: finding the direction of scrolling in UIScrollView

    - by Alex1987
    I have a UIScrollView with only horizontal scrolling allowed, and I would like to know which direction (left, right) the user scrolls. What I did was to subclass the UIScrollView and override the touchesMoved method: - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesMoved:touches withEvent:event]; UITouch *touch = [touches anyObject]; float now = [touch locationInView:self].x; float before = [touch previousLocationInView:self].x; NSLog(@"%f %f", before, now); if (now > before){ right = NO; NSLog(@"LEFT"); } else{ right = YES; NSLog(@"RIGHT"); } } But this method sometimes doesn't get called at all when I move. What do you think?

    Read the article

  • iOS: Gesture recogniser for smooth scrolling and flicking a View

    - by AppleDeveloper
    I am building an iPad app where I needed to allow resizing views functionality using divider view provided between two views. This divider view is just a 20px height view between two half screen content views - please refer attached images. When user scrolls this divider view up or down, both content views changes their sizes appropriately. I have extended UIView and implemented this using touchMoved delegate as code given below in touchesMoved delegate. It works fine. The only thing is missing with TouchMoved is you can't flick divider view to top or bottom directly. You have to scroll all the way to top or bottom! To support flicking the view I have tried UIPanGestureRecognizer but I don't see smooth scrolling with it. When I handle split position change in UIGestureRecognizerStateChanged state, just touching divider view flick it to top or bottom. Handling split position change in UIGestureRecognizerStateEnded does the same but I don't see content view resizing with dividerview scrolling! Could someone please tell me how could I achieve both smooth scrolling of divider view with resizing content views(like touchMoved) and flicking the view. Any alternative approach would also fine. Thanks. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; if (touch) { CGPoint lastPt = [touch previousLocationInView:self]; CGPoint pt = [touch locationInView:self]; float offset = pt.y - lastPt.y; self.parentViewController.splitPosition = self.parentViewController.splitPosition + offset; } } - (void)handlePan:(UIPanGestureRecognizer*)recognizer { CGPoint translation = [recognizer translationInView:recognizer.view]; CGPoint velocity = [recognizer velocityInView:recognizer.view]; if (recognizer.state == UIGestureRecognizerStateBegan) { } else if (recognizer.state == UIGestureRecognizerStateChanged) { // If I change split position here, I don't see smooth scrolling dividerview...it directly jumps to the top or bottom! self.parentViewController.splitPosition = self.parentViewController.splitPosition + translation.y; } else if (recognizer.state == UIGestureRecognizerStateEnded) { // If I change split position here, the same thing happens at end and I don't see my divider view moving with my scrolling and resizing my views. self.parentViewController.splitPosition = self.parentViewController.splitPosition + translation.y; } } Initial screen Increased top view size by scrolling divider view Top view is totally hidden here but I have to scroll divider view all the way to top. I want to flick the divider view so that it directly goes from any position to top

    Read the article

  • Disabling Magnifying Glass in UITextView in an iPhone App

    - by tgm
    I want to display text and I want to be able to know where in this text a user touches. Because the text could be long, I wanted to use a UITextView so that wrapping and everything would be taken care of. I want my own event handling for when a touch begins or moves. My problem is that the magnifying glass and select/select all menu are interrupting my touchesMoved events. How can i disable the magnifying glass, but still have user interaction enabled so that I can detect the touches?

    Read the article

  • How to add images while moving finger across UIView?

    - by Luke Irvin
    I am having issues adding an image across a view while moving finger across the screen. Currently it is adding the image multiple times but squeezing them too close together and not really following my touch. Here is what I am trying: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch * touch = [touches anyObject]; touchPoint = [touch locationInView:imageView]; if (touchPoint.x > 0 && touchPoint.y > 0) { _aImageView = [[UIImageView alloc] initWithImage:aImage]; _aImageView.multipleTouchEnabled = YES; _aImageView.userInteractionEnabled = YES; [_aImageView setFrame:CGRectMake(touchPoint.x, touchPoint.y, 80.0, 80.0)]; [imageView addSubview:_aImageView]; [_aImageView release]; } } -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [self touchesBegan:touches withEvent:event]; } Any suggestions is much appreciated. EDIT: What I want: After taking or choosing an image, the user can then select another image from a list. I want the user to touch and move their finger across the view and the selected image will appear where they drag their finger, without overlapping, in each location.

    Read the article

  • iPhone "touchesBegan" and "touchesMoved" message ... do not move to centre of touch

    - by Nippysaurus
    I am modifying the "MoveMe" example from the apple web site. When I get the "touchesMoved" message I move the centre of the target view to the centre of the touch. Is there a way that when the touch starts ("touchesBegan" message) I can remember the offset from the target view and keep that offset. Let me know if this is hard to understand and I will try to explain it a bit better.

    Read the article

  • Cancel UITouch Events When View Covered By Modal UIViewController

    - by kkrizka
    Hi there, I am writing an application where the user has to move some stuff on the screen using his fingers and drop them. To do this, I am using the touchesBegan,touchesEnded... function of each view that has to be moved. The problem is that sometimes the views are covered by a view displayed using the [UIViewController presentModalViewController] function. As soon as that happens, the UIView that I was moving stops receiving the touch events, since it was covered up. But there is no event telling me that it stopped receiving the events, so I can reset the state of the moved view. The following is an example that demonstrates this. The functions are part of a UIView that is being shown in the main window. It listens to touch events and when I drag the finger for some distance, it presents a modal view that covers everything. In the Run Log, it prints what touch events are received. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touchesBegan"); touchStart=[[touches anyObject] locationInView:self]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint touchAt=[[touches anyObject] locationInView:self]; float xx=(touchAt.x-touchStart.x)*(touchAt.x-touchStart.x); float yy=(touchAt.y-touchStart.y)*(touchAt.y-touchStart.y); float rr=xx+yy; NSLog(@"touchesMoved %f",rr); if(rr > 100) { NSLog(@"Show modal"); [viewController presentModalViewController:[UIViewController new] animated:NO]; } } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touchesEnded"); } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touchesCancelled"); } But when I test the application and trigger the modal dialog to be displayed, the following is the output in the Run Log. [Session started at 2010-03-27 16:17:14 -0700.] 2010-03-27 16:17:18.831 modelTouchCancel[2594:207] touchesBegan 2010-03-27 16:17:19.485 modelTouchCancel[2594:207] touchesMoved 2.000000 2010-03-27 16:17:19.504 modelTouchCancel[2594:207] touchesMoved 4.000000 2010-03-27 16:17:19.523 modelTouchCancel[2594:207] touchesMoved 16.000000 2010-03-27 16:17:19.538 modelTouchCancel[2594:207] touchesMoved 26.000000 2010-03-27 16:17:19.596 modelTouchCancel[2594:207] touchesMoved 68.000000 2010-03-27 16:17:19.624 modelTouchCancel[2594:207] touchesMoved 85.000000 2010-03-27 16:17:19.640 modelTouchCancel[2594:207] touchesMoved 125.000000 2010-03-27 16:17:19.641 modelTouchCancel[2594:207] Show modal Any suggestions on how to reset the state of a UIView when its touch events are interrupted by a modal view?

    Read the article

  • Create a screen like the iPhone home screen with Scrollview and Buttons

    - by Anthony Chan
    Hi, I'm working on a project and need to create a screen similar to the iPhone home screen: A scrollview with multiple pages A bunch of icons When not in edit mode, swipe through different pages (even I started the touch on an icon) When not in edit mode, tap an icon to do something When in edit mode, drag the icon to swap places, and even swap to different pages When in edit mode, tap an icon to remove it Previously I read from several forums that I have to subclass UIScrollview in order to have touch input for the UIViews on top of it. So I subclassed it overriding the methods to handle touches: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { //If not dragging, send event to next responder if (!self.dragging) [self.nextResponder touchesBegan:touches withEvent:event]; else [super touchesBegan:touches withEvent:event]; } In general I've override the touchesBegan:, touchesMoved: and touchesEnded: methods similarly. Then in the view controller, I added to following code: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; UIView *hitView = (UIView *)touch.view; if ([hitView isKindOfClass:[UIView class]]) { [hitView doSomething]; NSLog(@"touchesBegan"); } } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { // Some codes to move the icons NSLog(@"touchesMoved"); } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touchesEnded"); } When I run the app, I have the touchesBegan method detected correctly. However, when I tried to drag the icon, the icon just moved a tiny bit and then the page started to scroll. In console, it logged with 2 or 3 "touchesMoved" message only. However, I learned from another project that it should logged tonnes of "touchesMoved" message as long as I'm still dragging on the screen. (I'm suspecting I have the delaysContentTouches set to YES, so it delays a little bit when I tried to drag the icons. After that minor delay, it sends to signal back to the scrollview to scroll through the page. Please correct me if I'm wrong.) So if any help on the code to perform the above tasks would be greatly appreciated. I've stuck in this place for nearly a week with no hope. Thanks a lot.

    Read the article

  • Detecting UITableView scrolling

    - by Xeph
    Hi I've subclassed UITableView (as KRTableView) and implemented the four touch-based methods (touchesBegan, touchesEnded, touchesMoved, and touchesCancelled) so that I can detect when a touch-based event is being handled on a UITableView. Essentially what I need to detect is when the UITableView is scrolling up or down. However, subclassing UITableView and creating the above methods only detects when scrolling or finger movement is occuring within a UITableViewCell, not on the entire UITableView. As soon as my finger is moved onto the next cell, the touch events don't do anything. This is how I'm subclassing UITableView: #import "KRTableView.h" @implementation KRTableView - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; NSLog(@"touches began..."); } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesMoved:touches withEvent:event]; NSLog(@"touchesMoved occured"); } - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent *)event { [super touchesCancelled:touches withEvent:event]; NSLog(@"touchesCancelled occured"); } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesEnded:touches withEvent:event]; NSLog(@"A tap was detected on KRTableView"); } @end How can I detect when the UITableView is scrolling up or down?

    Read the article

  • Passing touch events on to subviews

    - by Egil Jansson
    I have a view within a UIScrollView that loads an additional subview when the user presses a certain area. When this additional subview is visible, I want all touch events to be handled by this - and not by the scrollview. It seems like the first couple events are being handled by the subview, but then touchesCancelled is called and the scrollview takes over the touch detection. How can I make sure that the subview gets all the events as long as the movement activity is being performed on this view? This is my implementation on touchesMoved - which I thought would do the job... -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[touches allObjects] objectAtIndex:0]; CGPoint touchPt = [touch locationInView:self]; UIView *hitView = [self hitTest:touchPt withEvent:event]; UIView *mySubView = subviewCtrl.view; if(hitView == mySubView) { [subviewCtrl.view touchesMoved:touches withEvent:event]; } else { NSLog(@"Outside of view..."); } }

    Read the article

  • Kepping object in memory (iPhone SDK)

    - by Chris
    I am trying to create a UIImageView called theImageView in the touchesBegan method that I can then then move to a new location in touchesMoved. Currently I am receiving an "undeclared" error in touchesMoved where I set the new location for theImageView. What can I do to keep theImageView in memory between these two methods? - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { ... UIImageView *theImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]]; theImageView.frame = CGRectMake(263, 228, 193, 300); [theImageView retain]; ... } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { ... theImageView.frame = CGRectMake(300, 300, 193, 300); ... }

    Read the article

  • Keeping object in memory (iPhone SDK)

    - by Chris
    I am trying to create a UIImageView called theImageView in the touchesBegan method that I can then then move to a new location in touchesMoved. Currently I am receiving an "undeclared" error in touchesMoved where I set the new location for theImageView. What can I do to keep theImageView in memory between these two methods? - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { ... UIImageView *theImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]]; theImageView.frame = CGRectMake(263, 228, 193, 300); [theImageView retain]; ... } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { ... theImageView.frame = CGRectMake(300, 300, 193, 300); ... }

    Read the article

  • UIResponder Delays

    - by Dylan Copeland
    I have a UIView subclass that overrides UIResponder's touchesMoved: message. I've noticed that when I swipe my finger very quickly across the UIView, my touchesMoved: message only gets called every so often and not constantly getting messaged. Any ideas? Thanks.

    Read the article

  • How to pass touch from a UITextView to a UITableViewCell

    - by Martin
    I have a UITextView in a custom UITableViewCell. The textview works properly (scrolls, shows text, etc.) but I need the users to be able to tap the table cell and go to another screen. Right now, if you tap the edges of the table cell (i.e. outside the UItextView) the next view is properly called. But clearly inside the uitextview the touches are being captured and not forwarded to the table cell. I found a post that talked about subclassing UITextView to forward the touches. I tried that without luck. The implementation is below. I'm wondering if maybe a) the super of my textview isn't the uitableviewcell and thus I need to pass the touch some other way or b) If the super is the uitableviewcell if I need to pass something else? Any help would be much appreciated. #import "ScrollableTextView.h" @implementation ScrollableTextView - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if (parentScrollView) { [parentScrollView touchesBegan:touches withEvent:event]; } [super touchesBegan:touches withEvent:event]; } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { if (parentScrollView) { [parentScrollView touchesCancelled:touches withEvent:event]; } [super touchesCancelled:touches withEvent:event]; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if (parentScrollView) { [parentScrollView touchesEnded:touches withEvent:event]; } [super touchesEnded:touches withEvent:event]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if (parentScrollView) { [parentScrollView touchesMoved:touches withEvent:event]; } [super touchesMoved:touches withEvent:event]; } - (BOOL)canBecomeFirstResponder { return YES; } @end

    Read the article

  • Navigation view system with webview problem with touches!

    - by Gonçalo Falcão
    Hello i have search everything and i didn't figure this out! I have a tab bar controller with 5 navigation controlls, in one of the navigation control, i have a view, with a table view inside, and when i click that item i push a new view, that view have view -webview -view i create that second view(is transperant) because i need to handle a single tap to hide my toolbar and navigation bar, and the webview was eating all the touches! I put that view and implement on the view controller -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch* touch = [touches anyObject]; if(touch.tapCount == 2){ [NSObject cancelPreviousPerformRequestsWithTarget:self]; } [[wv.subviews objectAtIndex:0] touchesBegan:touches withEvent:event]; [super touchesBegan:touches withEvent:event]; } -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ [[wv.subviews objectAtIndex:0] touchesMoved:touches withEvent:event]; [super touchesMoved:touches withEvent:event]; } -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch* touch = [touches anyObject]; if(touch.tapCount == 1){ [self performSelector:@selector(hideBars) withObject:nil afterDelay:0.3]; } [[wv.subviews objectAtIndex:0] touchesEnded:touches withEvent:event]; [super touchesEnded:touches withEvent:event]; } -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ [[wv.subviews objectAtIndex:0] touchesCancelled:touches withEvent:event]; [super touchesCancelled:touches withEvent:event]; } wv is my UIWebView IBOutlet now i can get the the touches in my controller and send them to my webview. So i thought everything was working, i'm able to scroll, but now when i have links i'm not able to click them. And the webview is detecting the links i have made that test. So any other way to implements this to get the touches in the links, or i should change this workaround to hide the toolbars so i can have the full functionability of the webview? Thks for the help in advance.

    Read the article

  • zoomfactor value in CGAffineTransformMakeScale in iPhone

    - by suse
    Hello, 1) I'm doing pinch zoom on the UIImageView , how should i decide upon the zoomfactor value, because when the zoomfactor value goes beyond 0[i.e negative value]the image is gettig tilted, which i dont want it to happen. how to avoid this situation. 2) Y is the flickring kind of rotationis happening, Y not the smooth rotation? ll this be taken care by CGAffineTransformMakeScale(zoomfactor,zoomfactor);method? This is what i'm doing in my code: zoomFactor = 0;// Initially zoomfactor is set to zero - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@" Inside touchesBegan .................."); NSArray *twoTouches = [touches allObjects]; UITouch *first = [twoTouches objectAtIndex:0]; OPERATION = [self identifyOperation:touches :first]; NSLog(@"OPERATION : %d",OPERATION); if(OPERATION == OPERATION_PINCH){ //double touch pinch UITouch *second = [twoTouches objectAtIndex:1]; f_G_initialDistance = distanceBetweenPoints([first locationInView:self.view],[second locationInView:self.view]); } NSLog(@" leaving touchesBegan .................."); } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@" Inside touchesMoved ................."); NSArray *twoTouchPoints = [touches allObjects]; if(OPERATION == OPERATION_PINCH){ CGFloat currentDistance = distanceBetweenPoints([[twoTouchPoints objectAtIndex:0] locationInView:self.view],[[twoTouchPoints objectAtIndex:1] locationInView:self.view]); int pinchOperation = [self identifyPinchOperation:f_G_initialDistance :currentDistance]; G_zoomFactor = [self calculateZoomFactor:pinchOperation :G_zoomFactor]; [uiImageView_G_obj setTransform:CGAffineTransformMakeScale(G_zoomFactor, G_zoomFactor)]; [self.view bringSubviewToFront:resetButton]; [self.view bringSubviewToFront:uiSlider_G_obj]; f_G_initialDistance = currentDistance; } NSLog(@" leaving touchesMoved .................."); } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@" Inside touchesEnded .................."); NSArray *twoTouches = [touches allObjects]; UITouch *first = [twoTouches objectAtIndex:0]; if(OPERATION == OPERATION_PINCH){ //do nothing } NSLog(@" Leaving touchesEnded .................."); } Thank You.

    Read the article

  • How to track the touch vector?

    - by mystify
    I need to calculate the direction of dragging a touch, to determine if the user is dragging up the screen, or down the screen. Actually pretty simple, right? But: 1) Finger goes down, you get -touchesBegan:withEvent: called 2) Must wait until finger moves, and -touchesMoved:withEvent: gets called 3) Problem: At this point it's dangerous to tell if the user did drag up or down. My thoughts: Check the time and accumulate calculates vectors until it's secure to tell the direction of touch. Easy? No. Think about it: What if the user holds the finger down for 5 minutes on the same spot, but THEN decides to move up or down? BANG! Your code would fail, because it tried to determine the direction of touch when the finger didn't move really. Problem 2: When the finger goes down and stays at the same spot for a few seconds because the user is a bit in the wind and thinks about what to do now, you'll get a lot of -touchesMoved:withEvent: calls very likely, but with very minor changes in touch location. So my next thought: Do the accumulation in -touchesMoved:withEvent:, but only if a certain threshold of movement has been exceeded. I bet you have some better concepts in place?

    Read the article

  • obj-c classes and sub classes (Cocos2d) conversion

    - by Lewis
    Hi I'm using this version of cocos2d: https://github.com/krzysztofzablocki/CCNode-SFGestureRecognizers Which supports the UIGestureRecognizer within a CCLayer in a cocos2d scene like so: @interface HelloWorldLayer : CCLayer <UIGestureRecognizerDelegate> { } Now I want to make this custom gesture work within the scene, attaching it to a sprite in cocos2d: #import <Foundation/Foundation.h> #import <UIKit/UIGestureRecognizerSubclass.h> @protocol OneFingerRotationGestureRecognizerDelegate <NSObject> @optional - (void) rotation: (CGFloat) angle; - (void) finalAngle: (CGFloat) angle; @end @interface OneFingerRotationGestureRecognizer : UIGestureRecognizer { CGPoint midPoint; CGFloat innerRadius; CGFloat outerRadius; CGFloat cumulatedAngle; id <OneFingerRotationGestureRecognizerDelegate> target; } - (id) initWithMidPoint: (CGPoint) midPoint innerRadius: (CGFloat) innerRadius outerRadius: (CGFloat) outerRadius target: (id) target; - (void)reset; - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event; @end #include <math.h> #import "OneFingerRotationGestureRecognizer.h" @implementation OneFingerRotationGestureRecognizer // private helper functions CGFloat distanceBetweenPoints(CGPoint point1, CGPoint point2); CGFloat angleBetweenLinesInDegrees(CGPoint beginLineA, CGPoint endLineA, CGPoint beginLineB, CGPoint endLineB); - (id) initWithMidPoint: (CGPoint) _midPoint innerRadius: (CGFloat) _innerRadius outerRadius: (CGFloat) _outerRadius target: (id <OneFingerRotationGestureRecognizerDelegate>) _target { if ((self = [super initWithTarget: _target action: nil])) { midPoint = _midPoint; innerRadius = _innerRadius; outerRadius = _outerRadius; target = _target; } return self; } /** Calculates the distance between point1 and point 2. */ CGFloat distanceBetweenPoints(CGPoint point1, CGPoint point2) { CGFloat dx = point1.x - point2.x; CGFloat dy = point1.y - point2.y; return sqrt(dx*dx + dy*dy); } CGFloat angleBetweenLinesInDegrees(CGPoint beginLineA, CGPoint endLineA, CGPoint beginLineB, CGPoint endLineB) { CGFloat a = endLineA.x - beginLineA.x; CGFloat b = endLineA.y - beginLineA.y; CGFloat c = endLineB.x - beginLineB.x; CGFloat d = endLineB.y - beginLineB.y; CGFloat atanA = atan2(a, b); CGFloat atanB = atan2(c, d); // convert radiants to degrees return (atanA - atanB) * 180 / M_PI; } #pragma mark - UIGestureRecognizer implementation - (void)reset { [super reset]; cumulatedAngle = 0; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; if ([touches count] != 1) { self.state = UIGestureRecognizerStateFailed; return; } } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesMoved:touches withEvent:event]; if (self.state == UIGestureRecognizerStateFailed) return; CGPoint nowPoint = [[touches anyObject] locationInView: self.view]; CGPoint prevPoint = [[touches anyObject] previousLocationInView: self.view]; // make sure the new point is within the area CGFloat distance = distanceBetweenPoints(midPoint, nowPoint); if ( innerRadius <= distance && distance <= outerRadius) { // calculate rotation angle between two points CGFloat angle = angleBetweenLinesInDegrees(midPoint, prevPoint, midPoint, nowPoint); // fix value, if the 12 o'clock position is between prevPoint and nowPoint if (angle > 180) { angle -= 360; } else if (angle < -180) { angle += 360; } // sum up single steps cumulatedAngle += angle; // call delegate if ([target respondsToSelector: @selector(rotation:)]) { [target rotation:angle]; } } else { // finger moved outside the area self.state = UIGestureRecognizerStateFailed; } } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesEnded:touches withEvent:event]; if (self.state == UIGestureRecognizerStatePossible) { self.state = UIGestureRecognizerStateRecognized; if ([target respondsToSelector: @selector(finalAngle:)]) { [target finalAngle:cumulatedAngle]; } } else { self.state = UIGestureRecognizerStateFailed; } cumulatedAngle = 0; } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesCancelled:touches withEvent:event]; self.state = UIGestureRecognizerStateFailed; cumulatedAngle = 0; } @end Header file for view controller: #import "OneFingerRotationGestureRecognizer.h" @interface OneFingerRotationGestureViewController : UIViewController <OneFingerRotationGestureRecognizerDelegate> @property (nonatomic, strong) IBOutlet UIImageView *image; @property (nonatomic, strong) IBOutlet UITextField *textDisplay; @end then this is in the .m file: gestureRecognizer = [[OneFingerRotationGestureRecognizer alloc] initWithMidPoint: midPoint innerRadius: outRadius / 3 outerRadius: outRadius target: self]; [self.view addGestureRecognizer: gestureRecognizer]; Now my question is, is it possible to add this custom gesture into the cocos2d project found on that github, and if so, what do I need to change in the OneFingerRotationGestureRecognizerDelegate to get it to work within cocos2d. Because at the minute it is setup in a standard iOS project and not a cocos2d project and I do not know enough about UIViews and classing/ sub classing in obj-c to get this to work. Also it seems to inherit from a UIView where cocos2d uses CCLayer. Kind regards, Lewis. I also realise I may have not included enough code from the custom gesture project for readers to interpret it fully, so the full project can be found here: https://github.com/melle/OneFingerRotationGestureDemo

    Read the article

  • Get touches from UIScrollView

    - by Peter Lapisu
    Basically i want to subclass UIScrollView and hande the touches, however, the touch methods dont get called (i searched the web for a solution and i found out people pointing to override the hit test, what i did, but with no result :( ) .h @interface XScroller : UIScrollView @end .m - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { UIView *result = nil; for (UIView *child in self.subviews) { if ([child pointInside:point withEvent:event]) { if ((result = [child hitTest:point withEvent:event]) != nil) { break; } } } return result; } - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"BEGAN"); [super touchesBegan:touches withEvent:event]; } - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"MOVED"); [super touchesMoved:touches withEvent:event]; } - (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"ENDED"); [super touchesEnded:touches withEvent:event]; } - (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"CANCELED"); [super touchesCancelled:touches withEvent:event]; } none of the - (void) touches* methods get called, the scrolling works ok

    Read the article

1 2 3 4  | Next Page >