Search Results

Search found 196 results on 8 pages for 'nsset'.

Page 3/8 | < Previous Page | 1 2 3 4 5 6 7 8  | Next Page >

  • 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

  • Using iPhone Core Data to many Relationship

    - by BLeB
    When I define a to many relationship between entities in Xcode and then generate the data class from the entity I get a header with the following methods defined: @interface PriceList (CoreDataGeneratedAccessors) - (void)addItemsObject:(PriceListItem *)value; - (void)removeItemsObject:(PriceListItem *)value; - (void)addItems:(NSSet *)value; - (void)removeItems:(NSSet *)value; @end When I attempt to call addItemsObject with the following code a doesNotRecognizeSelector exception is thrown. PriceListItem *item = [NSEntityDescription insertNewObjectForEntityForName:@"PriceListItem" inManagedObjectContext:managedObjectContext]; item.cat = [attributeDict valueForKey:@"c"]; item.sel = [attributeDict valueForKey:@"s"]; [self addItemsObject:item]; From what I have read I do not have to implement these methods and that they are generated at runtime. Any ideas?

    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

  • Starting a SKProductsRequest gives -[_NSCFArray length] invalid selector error a moment later. LoadMicroPaymentsProductsOperation error.

    - by quantumpotato
    I'm fetching a list of identifiers from my server, then passing them off in a products request to Apple. Here's my code, and below is the error I'm getting. The iPhone 4 is not crashing when this happens. -(void)didReceiveData:(NSArray *)data { NSLog(@"Received Identifiers: %@",data); NSSet *productIdentifiers = [NSSet setWithArray:data]; SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers]; productsRequest.delegate = self; [productsRequest start]; NSLog(@"productsRequest should have started by now"); } Wed Dec 29 09:42:14 iPhone XXXX-iphone[6363] <Warning>: Received Identifiers: ( ( 1, 10, "com.XXXX.XXXX.10" ) ) Wed Dec 29 09:42:14 iPhone XXXX-iphone[6363] <Warning>: productsRequest should have started by now Wed Dec 29 09:42:18 iPhone itunesstored[6367] : -[__NSCFArray length]: unrecognized selector sent to instance 0x119070 Wed Dec 29 09:42:18 iPhone itunesstored[6367] : caught -[__NSCFArray length]: unrecognized selector sent to instance 0x119070 exception with stack trace: (0x33ac0975 0x3347b49d 0x33ac2133 0x33a69aa9 0x33a69860 0x2717b 0x27515 0x31469651 0x314693ed 0x31469e39 0x3362795f 0x336276c3 0x3363c4eb 0x33c32680 0x33c32ba0 0x33bd7251 0x33bcf978)

    Read the article

  • How To Draw line on touch event ?

    - by AJPatel
    Hey i m beginner of objective C Please Help me i make following code but not work..... -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; if ([touch view] == self.view) { CGPoint location = [touch locationInView:self.view]; loc1 = location; CGContextMoveToPoint(context, location.x, location.y); NSLog(@"x:%d y:%d At Touch Begain", loc1.x, loc1.y); } } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; if ([touch view] == self.view) { CGPoint location = [touch locationInView:self.view]; CGContextMoveToPoint(context, loc1.x, loc1.y); NSLog(@"x:%d y:%d At Touch Move", loc1.x, loc1.y); CGContextAddLineToPoint(context, location.x, location.y); NSLog(@"x:%d y:%d", location.x, location.y); } }

    Read the article

  • Rotate rectangle around center

    - by ESoft
    I am playing with Brad Larsen's adaption of the trackball app. I have two views at a 60 degree angle to each other and was wondering how I get the rotation to be in the center of this (non-closed) rectangle? In the images below I would have liked the rotation to take place all within the blue lines. Code (modified to only rotate around x axis): #import "MyView.h" //===================================================== // Defines //===================================================== #define DEGREES_TO_RADIANS(degrees) \ (degrees * (M_PI / 180.0f)) //===================================================== // Public Interface //===================================================== @implementation MyView - (void)awakeFromNib { transformed = [CALayer layer]; transformed.anchorPoint = CGPointMake(0.5f, 0.5f); transformed.frame = self.bounds; [self.layer addSublayer:transformed]; CALayer *imageLayer = [CALayer layer]; imageLayer.frame = CGRectMake(10.0f, 4.0f, self.bounds.size.width / 2.0f, self.bounds.size.height / 2.0f); imageLayer.transform = CATransform3DMakeRotation(DEGREES_TO_RADIANS(60.0f), 1.0f, 0.0f, 0.0f); imageLayer.contents = (id)[[UIImage imageNamed:@"IMG_0051.png"] CGImage]; imageLayer.borderColor = [UIColor yellowColor].CGColor; imageLayer.borderWidth = 2.0f; [transformed addSublayer:imageLayer]; imageLayer = [CALayer layer]; imageLayer.frame = CGRectMake(10.0f, 120.0f, self.bounds.size.width / 2.0f, self.bounds.size.height / 2.0f); imageLayer.transform = CATransform3DMakeRotation(DEGREES_TO_RADIANS(-60.0f), 1.0f, 0.0f, 0.0f); imageLayer.contents = (id)[[UIImage imageNamed:@"IMG_0089.png"] CGImage]; imageLayer.borderColor = [UIColor greenColor].CGColor; imageLayer.borderWidth = 2.0f; transformed.borderColor = [UIColor whiteColor].CGColor; transformed.borderWidth = 2.0f; [transformed addSublayer:imageLayer]; UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, self.bounds.size.height / 2.0f, self.bounds.size.width, 2)]; [line setBackgroundColor:[UIColor redColor]]; [self addSubview:line]; line = [[UIView alloc] initWithFrame:CGRectMake(0, self.bounds.size.height * (1.0f / 4.0f), self.bounds.size.width, 2)]; [line setBackgroundColor:[UIColor blueColor]]; [self addSubview:line]; line = [[UIView alloc] initWithFrame:CGRectMake(0, self.bounds.size.height * (3.0f / 4.0f), self.bounds.size.width, 2)]; [line setBackgroundColor:[UIColor blueColor]]; [self addSubview:line]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { previousLocation = [[touches anyObject] locationInView:self]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint location = [[touches anyObject] locationInView:self]; //location = CGPointMake(previousLocation.x, location.y); CATransform3D currentTransform = transformed.sublayerTransform; //CGFloat displacementInX = location.x - previousLocation.x; CGFloat displacementInX = previousLocation.x - location.x; CGFloat displacementInY = previousLocation.y - location.y; CGFloat totalRotation = sqrt((displacementInX * displacementInX) + (displacementInY * displacementInY)); CGFloat angle = DEGREES_TO_RADIANS(totalRotation); CGFloat x = ((displacementInX / totalRotation) * currentTransform.m12 + (displacementInY/totalRotation) * currentTransform.m11); CATransform3D rotationalTransform = CATransform3DRotate(currentTransform, angle, x, 0, 0); previousLocation = location; transformed.sublayerTransform = rotationalTransform; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { } - (void)dealloc { [super dealloc]; } @end

    Read the article

  • Cocoa threading question.

    - by Steve918
    I would like to implement an observer pattern in Objective-C where the observer implements an interface similar to SKPaymentTransactionObserver and the observable class just extends my base observable. My observable class looks something like what is below. Notice I'm making copies of the observers before enumeration to avoid throwing an exception . I've tried adding an NSLock around add observers and notify observers, but I run into a deadlock. What would be the proper way to handle concurrency when observers are being added as notifications are being sent? @implementation Observable -(void)notifyObservers:(SEL)selector { @synchronized(self) { NSSet* observer_copy = [observers copy]; for (id observer in observer_copy) { if([observer respondsToSelector: selector]) { [observer performSelector: selector]; } } [observer_copy release]; } } -(void)notifyObservers:(SEL)selector withObject:(id)arg1 withObject:(id)arg2 { @synchronized(self) { NSSet* observer_copy = [observers copy]; for (id observer in observer_copy) { if([observer respondsToSelector: selector]) { [observer performSelector: selector withObject: arg1 withObject: arg2]; } } [observer_copy release]; } } -(void)addObserver:(id)observer { @synchronized(self) { [observers addObject: observer]; } } -(void)removeObserver:(id)observer { @synchronized(self) { [observers removeObject: observer]; } }

    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

  • touchesBegin & touchesMove Xcode Obj C Question

    - by AndrewDK
    So I have my app working good when you press and drag along. I also have UIButtons set to Touch Down in Interface Builder. As well when you drag you need to drag from the outside of the UIButton. You cannot click on the UIButton and drag to the other. TOUCHES MOVED: Code: -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event touchesForView:self.view] anyObject]; CGPoint location = [touch locationInView:touch.view]; if(CGRectContainsPoint(oneButton.frame, location)) { if (!oneButton.isHighlighted){ [self oneFunction]; [oneButton setHighlighted:YES]; } }else { [oneButton setHighlighted:NO]; } // if(CGRectContainsPoint(twoButton.frame, location)) { if (!twoButton.isHighlighted){ [self twoFunction]; [twoButton setHighlighted:YES]; } }else { [twoButton setHighlighted:NO]; } } TOUCHES BEGAN: Code: - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event touchesForView:self.view] anyObject]; CGPoint location = [touch locationInView:touch.view]; if(CGRectContainsPoint(oneButton.frame, location)) { [self oneFunction]; [oneButton setHighlighted:YES]; } if(CGRectContainsPoint(twoButton.frame, location)) { [self twoFunction]; [twoButton setHighlighted:YES]; } } I want to be able to click on any of the button fire the function & also be able to drag from one button on to the other and fire that function. So basically just being able to click on a button and slide your finger over and activate the other button without having to press and slide from outside of the button. I think I'm close, need a bit of help. Hope thats clear enough. Thanks.

    Read the article

  • Add double tap action (presentModalViewController) to UISCOLLVIEW

    - by R.J.
    I have been wrestling this issue for a while now and cannot seem to get the following "touchesEnded" method to execute within a UISCROLLVIEW. I have read on many of the forums that UISCROLLVIEW will take control of all touch events unless it is subclassed, but I cannot seem to get the code right (still new to the SDK). Basically I have a scrollview made uo with several UIIMAGEVIEW's and currenlty have scrolling with paging (much like the photo app). I have been studying the SCROLLING MADDNESS example without success. All I want to do is anywhere in the UISCROLLVIEW have the user double tap to presentModalViewController back to my info page (i.e.) (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSSet *allTouches = [event allTouches]; switch ([allTouches count]) { case 1: {// One finger touch UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; if ([touch tapCount] == 2) {InfoButtonViewController *scroll = [[InfoButtonViewController alloc] initWithNibName:nil bundle:nil]; scroll.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:scroll animated:YES]; [scroll release]; } } } } Any code assistance would be greatly appreciated. The UISCROLLVIEW is implemented as follows (let me know if I need to provide additional details). Thank you in advance... MyViewController.h @interface MyViewController : UIViewController { } @end

    Read the article

  • iPhone - how to track touches and allow button taps at the same time?

    - by Jonathan Cohen
    I'm wondering how to track touches anywhere on the iPhone screen and still have UIButtons respond to taps. I subclassed a UIView, made it full screen and the highest view in the hierarchy, and overrode its pointInside:withEvent method. If I return YES, I'm able to track touches anywhere on the screen but the buttons don't respond (likely because the view is instructed to handle and terminate the touch). If I return NO, the touch passes through the view and the buttons respond, but I'm not able to track touches. Do I need to subclass UIButton or is this possible through the responder chain? What am I doing wrong? - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{ return NO; } //only works if pointInside:withEvent: returns YES. -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"began"); [self.nextResponder touchesBegan:touches withEvent:event]; } //only works if pointInside:withEvent: returns YES. -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"end"); [self.nextResponder touchesEnded:touches withEvent:event]; }

    Read the article

  • How can I load a view based on how long I hold a UIButton?

    - by Thomas
    Hello all, I've searched the net and documentation, but haven't found anything quite like what I'm trying to do. I'm working on an app where I want to load one view if a UIButton is held for x seconds, another if it's held for x+y seconds, etc. I found this tutorial. The problem I'm running into is, how do I switch the length of the button press? The tutorial switched the number of taps. -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSSet *allTouches = [event allTouches]; switch ([allTouches count]) { case 1: // Single touch { // Get the first touch. UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; switch ([touch tapCount]) { case 1: // Single Tap. { // Start a timer timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showAlertView:) userInfo:nil repeats:NO]; [timer retain]; } break; case 2: // Double tap. break; } } break; case 2: // Double touch { } break; default: break; } } Any suggestions? Thanks! Thomas

    Read the article

  • How to allow one thread to mutate an array property while another thread iterates on a copy of the a

    - by Steve918
    I would like to implement an observer pattern in Objective-C where the observer implements an interface similar to SKPaymentTransactionObserver and the observable class just extends my base observable. My observable class looks something like what is below. Notice I'm making copies of the observers before enumeration to avoid throwing an exception . I've tried adding an NSLock around add observers and notify observers, but I run into a deadlock. What would be the proper way to handle concurrency when observers are being added as notifications are being sent? @implementation Observable -(void)notifyObservers:(SEL)selector { @synchronized(self) { NSSet* observer_copy = [observers copy]; for (id observer in observer_copy) { if([observer respondsToSelector: selector]) { [observer performSelector: selector]; } } [observer_copy release]; } } -(void)notifyObservers:(SEL)selector withObject:(id)arg1 withObject:(id)arg2 { @synchronized(self) { NSSet* observer_copy = [observers copy]; for (id observer in observer_copy) { if([observer respondsToSelector: selector]) { [observer performSelector: selector withObject: arg1 withObject: arg2]; } } [observer_copy release]; } } -(void)addObserver:(id)observer { @synchronized(self) { [observers addObject: observer]; } } -(void)removeObserver:(id)observer { @synchronized(self) { [observers removeObject: observer]; } }

    Read the article

  • Objective-C Getter Memory Management

    - by Marian André
    I'm fairly new to Objective-C and am not sure how to correctly deal with memory management in the following scenario: I have a Core Data Entity with a to-many relationship for the key "children". In order to access the children as an array, sorted by the column "position", I wrote the model class this way: @interface AbstractItem : NSManagedObject { NSArray * arrangedChildren; } @property (nonatomic, retain) NSSet * children; @property (nonatomic, retain) NSNumber * position; @property (nonatomic, retain) NSArray * arrangedChildren; @end @implementation AbstractItem @dynamic children; @dynamic position; @synthesize arrangedChildren; - (NSArray*)arrangedChildren { NSArray* unarrangedChildren = [[self.children allObjects] retain]; NSSortDescriptor* sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"position" ascending:YES]; [arrangedChildren release]; arrangedChildren = [unarrangedChildren sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]; [sortDescriptor release]; [unarrangedChildren release]; return [arrangedChildren retain]; } @end I'm not sure whether or not to retain unarrangedChildren and the returned arrangedChildren (first and last line of the arrangedChildren getter). Does the NSSet allObjects method already return a retained array? It's probably too late and I have a coffee overdose. I'd be really thankful if someone could point me in the right direction. I guess I'm missing vital parts of memory management knowledge and I will definitely look into it thoroughly.

    Read the article

  • BWToolkit inclusion crashing

    - by Schroedinger
    Hey guys I'm using the latest version of XCode (3.2.2) and I've linked the framework using the tutorial. I was building my app and tested it and I get a BWToolkit exception on decoding. I've included the Framework in the frameworks and added it to the copy files stage. I even created a new dummy app including the framework and adding it to the copy files stage and it still crashes when I try to run. Any ideas? Do I need to include it somewhere in the app? I'm worried I've overlooked something really simple. 2010-04-13 14:14:24.540 BWTestFramework[7504:a0f] An uncaught exception was raised 2010-04-13 14:14:24.543 BWTestFramework[7504:a0f] *** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (BWSplitView) 2010-04-13 14:14:24.545 BWTestFramework[7504:a0f] *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (BWSplitView)' *** Call stack at first throw: ( 0 CoreFoundation 0x00007fff84a77d24 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x00007fff82ba00f3 objc_exception_throw + 45 2 CoreFoundation 0x00007fff84a77b47 +[NSException raise:format:arguments:] + 103 3 CoreFoundation 0x00007fff84a77ad4 +[NSException raise:format:] + 148 4 Foundation 0x00007fff83804aa6 _decodeObjectBinary + 2427 5 Foundation 0x00007fff83805825 -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:] + 1229 6 Foundation 0x00007fff83805d65 -[NSArray(NSArray) initWithCoder:] + 462 7 Foundation 0x00007fff83804b1f _decodeObjectBinary + 2548 8 Foundation 0x00007fff83803f99 _decodeObject + 208 9 AppKit 0x00007fff8069fbfb -[NSView initWithCoder:] + 362 10 Foundation 0x00007fff83804b1f _decodeObjectBinary + 2548 11 Foundation 0x00007fff83803f99 _decodeObject + 208 12 AppKit 0x00007fff806adfbb -[NSWindowTemplate initWithCoder:] + 3824 13 Foundation 0x00007fff83804b1f _decodeObjectBinary + 2548 14 Foundation 0x00007fff83805825 -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:] + 1229 15 Foundation 0x00007fff83805268 -[NSSet(NSSet) initWithCoder:] + 447 16 Foundation 0x00007fff83804b1f _decodeObjectBinary + 2548 17 Foundation 0x00007fff83803f99 _decodeObject + 208 18 AppKit 0x00007fff8062fcde -[NSIBObjectData initWithCoder:] + 1983 19 Foundation 0x00007fff83804b1f _decodeObjectBinary + 2548 20 Foundation 0x00007fff83803f99 _decodeObject + 208 21 AppKit 0x00007fff8062f40d loadNib + 146 22 AppKit 0x00007fff8062e96d +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 248 23 AppKit 0x00007fff8062e7a5 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 326 24 AppKit 0x00007fff8062bd27 NSApplicationMain + 279 25 BWTestFramework 0x0000000100001891 main + 33 26 BWTestFramework 0x0000000100001868 start + 52 ) terminate called after throwing an instance of 'NSException' That's the crash report

    Read the article

  • changing sounds when objects meet

    - by blacksheep
    i'd like to change sounds when tapping on an image and drag another image over several others. it is not working properly: the "MoveImage" is not dragable, the tapping is working outside the "TouchImage" and the sounds do not change when tapping on it. (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch = [[event allTouches] anyObject]; CGPoint location = [touch locationInView:touch.view]; if(((CGRectContainsPoint(myTouchImage.frame, location)), (CGRectIntersectsRect(myMoveImage.frame,myImage_1.frame)))) { [sound_E play]; } if (((CGRectContainsPoint(myTouchImage.frame, location)), (CGRectIntersectsRect(myMoveImage.frame,myImage_2.frame)))) { [sound_F play]; } if (((CGRectContainsPoint(myTouchImage.frame, location)), (CGRectIntersectsRect(myMoveImage.frame,myImage_3.frame)))) { [sound_D play]; } if (((CGRectContainsPoint(myTouchImage.frame, location)), (CGRectIntersectsRect(myMoveImage.frame,myImage_4.frame)))) { [sound_Dis play]; } } (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint location = [touch locationInView:touch.view]; if (CGRectContainsPoint(myMoveImage.frame, location)){ CGPoint yLocation = CGPointMake(myMoveImage.center.x,location.y); myMoveImage.center = yLocation; } if(CGRectIntersectsRect(myMoveImage.frame,myImage_1.frame)) { E_NOTE.text = @"E"; } if(CGRectIntersectsRect(myMoveImage.frame,myImage_2.frame)) { F_NOTE.text = @"F"; } if(CGRectIntersectsRect(myMoveImage.frame,myImage_3.frame)) { D_NOTE.text = @"D"; } if(CGRectIntersectsRect(myMoveImage.frame,myImage_4.frame)) { Dis_NOTE.text = @"D#"; } }

    Read the article

  • Problems with CGPoint/touches event

    - by Jason
    I'm having some problems with storing variables from my touch events. The warning I get when I run this is that coord and icoord are unused, but I used them in the viewDidLoad implementation, is there a reason why this does not work? Any suggestions? #import "iGameViewController.h" @implementation iGameViewController @synthesize player; -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint icoord = [touch locationInView:touch.view]; } -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint coord = [touch locationInView:touch.view]; } - (void)viewDidLoad { if (coord.x > icoord.x) { player.center = CGPointMake(player.center.x + 5, player.center.y); } if (coord.x < icoord.x) { player.center = CGPointMake(player.center.x - 5, player.center.y); } if (coord.y > icoord.y) { player.center = CGPointMake(player.center.x, player.center.y - 5); } if (coord.y < icoord.y) { player.center = CGPointMake(player.center.x, player.center.y + 5); } } Thanks.

    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

  • Troubles moving a UIView.

    - by Joshua
    I have been trying to move a UIView by following a users touch. I have almost got it to work except for one thing, the UIView keeps flicking between two places. Here's the code I have been using: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touchDown"); UITouch *touch = [touches anyObject]; firstTouch = [touch locationInView:self.view]; lastTouch = [touch locationInView:self.view]; [self.view setNeedsDisplay]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { InSightViewController *contentView = [[InSightViewController alloc] initWithNibName:@"SubView" bundle:[NSBundle mainBundle]]; [contentView loadView]; UITouch *touch = [touches anyObject]; currentTouch = [touch locationInView:self.view]; if (CGRectContainsPoint(contentView.view.bounds, firstTouch)) { NSLog(@"touch in subView/contentView"); sub.frame = CGRectMake(currentTouch.x - 50.0, currentTouch.y, 130.0, 21.0); } NSLog(@"touch moved"); lastTouch = currentTouch; [self.view setNeedsDisplay]; } And here's what's been happening: http://cl.ly/Sjx

    Read the article

  • tracking the position of dragview

    - by user262325
    Hello everyone I put a dragview on an UIView, I hope when I drag the dragview, its superview (UIView) tracks the position of the dragview and moves itself to the position where to keep dragview at the original position on the UIView. The codes show below: #import <UIKit/UIKit.h> @interface DragView : UIImageView { CGPoint startLocation; } @end #import "DragView.h" @implementation DragView - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { // Initialization code } return self; } - (void)drawRect:(CGRect)rect { // Drawing code } -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event { CGPoint pt=[[touches anyObject] locationInView:self]; startLocation=pt; [[self superview] bringSubviewToFront:self]; } -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint pt=[[touches anyObject] locationInView:self]; CGRect frame=[self frame]; frame.origin.x+=pt.x-startLocation.x; frame.origin.y+=pt.y-startLocation.y; CGRect frame1=[[self superview] frame];//superview of the dragview frame1.origin.x+=frame.origin.x; //tracks the postion of dragview frame1.origin.y+=frame.origin.y; [[self superview] setFrame: frame1 ]; //move to new position [self setFrame:frame]; } my problem is that the UIView moved but lagged to the movement of the drageview(RED BLOCK). Welcome any comment Thanks interdev

    Read the article

  • Is there a more efficient way to do this?

    - by garethdn
    I'm hoping there is a better way to the following. I'm creating a jigsaw-type application and this is the current code i'm using: -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; //location of current touch CGPoint location = [touch locationInView:self.view]; if ([touch view] == img1) { [self animateFirstTouch:img1 withLocation:location]; } else if ([touch view] == img2) { [self animateFirstTouch:img2 withLocation:location]; } else if ([touch view] == img3) { [self animateFirstTouch:img3 withLocation:location]; } else if ([touch view] == img4) { [self animateFirstTouch:img4 withLocation:location]; } else if { ...... ...... } else if ([touch view] == img40) { [self animateFirstTouch:img40 withLocation:location]; return; } } I'm hoping that there is a better, more efficieny way to do this, rather than naming every image. I'm thinking something like, if touch view is equal to a UIImageView, then perform some task. The same for touchesEnded: -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; //location of current touch CGPoint location = [touch locationInView:self.view]; if ([touch view] == image1) { [self animateReleaseTouch:image1 withLocation:location]; } else if ([touch view] == image2) { [self animateReleaseTouch:image2 withLocation:location]; } else if ([touch view] == image3) { [self animateReleaseTouch:image3 withLocation:location]; } else if ([touch view] == image4) { [self animateReleaseTouch:image4 withLocation:location]; } else if{ ...... ...... } else if ([touch view] == image40) { [self animateReleaseTouch:image40 withLocation:location]; } return; } Any help please?

    Read the article

  • Draggable cards (touch enumeration) issue

    - by glitch
    I'm trying to let a player tap, drag and release a card from a fanned stack on the screen to a 4x4 field on the board. My cards are instantiated from a custom class that inherits from the UIImageView class. I started with the Touches sample app, and I modified the event handlers for touches to iterate over my player's card hand instead of the 3 squares the sample app allows you to move on screen. Everything works, until that is, I move the card I'm dragging near another card. I'm really drawing a blank here for the logic to get the cards to behave properly. Here's my code: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSUInteger numTaps = [[touches anyObject] tapCount]; if(numTaps = 1) { for (UITouch *touch in touches) { [self dispatchFirstTouchAtPoint:[touch locationInView: self.boardCardView] forEvent:nil]; } } } -(void) dispatchFirstTouchAtPoint:(CGPoint)touchPoint forEvent:(UIEvent *)event { for (int i = 0; i<5; i++) { UIImageView *touchedCard = boardBuffer[i]; if (CGRectContainsPoint([touchedCard frame], touchPoint)) { [self animateFirstTouchAtPoint:touchPoint forView:touchedCard]; } } } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { NSUInteger touchCount = 0; for (UITouch *touch in touches){ [self dispatchTouchEvent:[touch view] toPosition:[touch locationInView:self.boardCardView]]; touchCount++; } } My questions are: How do I get the touch logic to disallow other cards from being picked up by a dragging finger? Is there anyway I can only enumerate the objects that are directly below a player's finger and explicitly disable other objects from responding? Thanks!

    Read the article

  • Save many-to-one relationship from JSON into Core Data

    - by Snow Crash
    I'm wanting to save a Many-to-one relationship parsed from JSON into Core Data. The code that parses the JSON and does the insert into Core Data looks like this: for (NSDictionary *thisRecipe in recipes) { Recipe *recipe = [NSEntityDescription insertNewObjectForEntityForName:@"Recipe" inManagedObjectContext:insertionContext]; recipe.title = [thisRecipe objectForKey:@"Title"]; NSDictionary *ingredientsForRecipe = [thisRecipe objectForKey:@"Ingredients"]; NSArray *ingredientsArray = [ingredientsForRecipe objectForKey:@"Results"]; for (NSDictionary *thisIngredient in ingredientsArray) { Ingredient *ingredient = [NSEntityDescription insertNewObjectForEntityForName:@"Ingredient" inManagedObjectContext:insertionContext]; ingredient.name = [thisIngredient objectForKey:@"Name"]; } } NSSet *ingredientsSet = [NSSet ingredientsArray]; [recipe setIngredients:ingredientsSet]; Notes: "setIngredients" is a Core Data generated accessor method. There is a many-to-one relationship between Ingredients and Recipe However, when I run this I get the following error: NSCFDictionary managedObjectContext]: unrecognized selector sent to instance If I remove the last line (i.e. [recipe setIngredients:ingredientsSet];) then, taking a peek at the SQLite database, I see the Recipe and Ingredients have been stored but no relationship has been created between Recipe and Ingredients Any suggestions as to how to ensure the relationship is stored correctly?

    Read the article

  • How may I monitor all gestures of the entire system

    - by Jiulong Zhao
    I can make a view to accept touch event and receive detailed gesture event like this: [self setAcceptsTouchEvents:YES]; // NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:self]; I can also receive global event by crate a monitor in this way: NSUInteger eventMasks = NSEventTypeBeginGesture | NSEventTypeEndGesture | NSEventMaskGesture; [NSEvent addGlobalMonitorForEventsMatchingMask:eventMasks handler:^(NSEvent *theevent) {//do something}]; But I can NOT get the detailed event from monitor by -touchesMatchingPhase How may I monitor all gestures of the entire system.

    Read the article

  • Smoothly drag a Sprite in cocos2d - iPhone

    - by Saurabh
    Hi All I have implemented a drag on a sprite object as follows.. -(BOOL)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch * touch = [touches anyObject]; CGPoint location = [[Director sharedDirector] convertCoordinate: [touch locationInView:touch.view]]; [diskSprite setPosition:ccp(location.x , location.y )]; return kEventHandled; } but this dragging is not smooth..... when i drag fast with my thumb the object left from the path. Thanks

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8  | Next Page >