Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-29-2011, 07:41 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 9
ahan.tm is on a distinguished road
Default Dragging Of UIImageViews Choppy And Slow

Hi,

When I use the following code to manage image dragging and collisions, they are choppy and do not drag right:
Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    marblebeingdragged = NO;
    UITouch *touch = [[event touchesForView:self.view] anyObject];
    CGPoint location = [touch locationInView:touch.view];
    
    
    if(CGRectContainsPoint(plusone.frame, location) && marblebeingdragged == NO)  //Drag Plus One
    {
        marblebeingdragged = YES;
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint location = [touch locationInView:touch.view];
        plusone.center = location;
    }
    if(CGRectContainsPoint(plustwo.frame, location) && marblebeingdragged == NO) //Drag Plus Two
    {
        
        marblebeingdragged = YES;
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint location = [touch locationInView:touch.view];
        plustwo.center = location;
        
    }
    if(CGRectContainsPoint(plusthree.frame, location) && marblebeingdragged == NO) //Drag Plus Three
    {
        
        //marblebeingdragged = YES;
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint location = [touch locationInView:touch.view];
        plusthree.center = location;
        
    }
    if(CGRectContainsPoint(minusone.frame, location) && marblebeingdragged == NO) //Drag Minus One
    {
        
        marblebeingdragged = YES;
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint location = [touch locationInView:touch.view];
        minusone.center = location;
        
    }
    if(CGRectContainsPoint(minustwo.frame, location) && marblebeingdragged == NO) //Drag Minus Two
    {
        marblebeingdragged = YES;
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint location = [touch locationInView:touch.view];
        minustwo.center = location;
        
    }
    if(CGRectContainsPoint(minusthree.frame, location) && marblebeingdragged == NO) //Drag Minus Three
    {
        marblebeingdragged = YES;
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint location = [touch locationInView:touch.view];
        minusthree.center = location;
    }
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    [self touchesBegan:touches withEvent:event];
    marblebeingdragged = NO;
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    if (CGRectIntersectsRect(striker.frame, plusone.frame)) { //Plus One Collision
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); //iPhone Vibrate
        
        marbles = 1+marbles; // Add 1 To Marbles
        marblesleft = marblesneeded - marbles;
        marblesNeeded.text = [NSString stringWithFormat:@"%i", marblesleft];
        NSNumber *marbleNumber = [NSNumber numberWithInt:marbles];
        
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef soundFileURLRef;
        soundFileURLRef =CFBundleCopyResourceURL(mainBundle, 
                                                 (CFStringRef) @"1 Marble", CFSTR ("aif"), NULL); //Sound Stuff
        
        UInt32 soundID;
        AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
        AudioServicesPlaySystemSound(soundID);
        
        [[records objectAtIndex:pageControl.currentPage] setValue:marbleNumber forKey:@"marbles"]; //Set Marble Value
        [self checkPrizeReached];
        NSError *error;
        [_managedObjectContext save:&error]; //Save 
        
        [UIView beginAnimations:nil context:nil]; //Move To Start Position With Animation
        [UIView setAnimationDuration:0.5];
        plusone.center = CGPointMake(36, 46);
        [UIView commitAnimations];
        marblebeingdragged = NO;
    } else
    {
        marblebeingdragged = YES;
    }
Please Note That The Code Is Cutoff, and touchesEnded is repeated with UIImageView changes.

This has only started when I began working with iOS 5. The images drag fine in the iOS 4.3 Simulator. Is there something wrong?

Thanks
ahan.tm is offline   Reply With Quote
Old 11-29-2011, 07:49 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by ahan.tm View Post
Hi,

When I use the following code to manage image dragging and collisions, they are choppy and do not drag right:
Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    marblebeingdragged = NO;
    UITouch *touch = [[event touchesForView:self.view] anyObject];
    CGPoint location = [touch locationInView:touch.view];
    
    
    if(CGRectContainsPoint(plusone.frame, location) && marblebeingdragged == NO)  //Drag Plus One
    {
        marblebeingdragged = YES;
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint location = [touch locationInView:touch.view];
        plusone.center = location;
    }
    if(CGRectContainsPoint(plustwo.frame, location) && marblebeingdragged == NO) //Drag Plus Two
    {
        
        marblebeingdragged = YES;
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint location = [touch locationInView:touch.view];
        plustwo.center = location;
        
    }
    if(CGRectContainsPoint(plusthree.frame, location) && marblebeingdragged == NO) //Drag Plus Three
    {
        
        //marblebeingdragged = YES;
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint location = [touch locationInView:touch.view];
        plusthree.center = location;
        
    }
    if(CGRectContainsPoint(minusone.frame, location) && marblebeingdragged == NO) //Drag Minus One
    {
        
        marblebeingdragged = YES;
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint location = [touch locationInView:touch.view];
        minusone.center = location;
        
    }
    if(CGRectContainsPoint(minustwo.frame, location) && marblebeingdragged == NO) //Drag Minus Two
    {
        marblebeingdragged = YES;
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint location = [touch locationInView:touch.view];
        minustwo.center = location;
        
    }
    if(CGRectContainsPoint(minusthree.frame, location) && marblebeingdragged == NO) //Drag Minus Three
    {
        marblebeingdragged = YES;
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint location = [touch locationInView:touch.view];
        minusthree.center = location;
    }
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    [self touchesBegan:touches withEvent:event];
    marblebeingdragged = NO;
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    if (CGRectIntersectsRect(striker.frame, plusone.frame)) { //Plus One Collision
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); //iPhone Vibrate
        
        marbles = 1+marbles; // Add 1 To Marbles
        marblesleft = marblesneeded - marbles;
        marblesNeeded.text = [NSString stringWithFormat:@"%i", marblesleft];
        NSNumber *marbleNumber = [NSNumber numberWithInt:marbles];
        
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef soundFileURLRef;
        soundFileURLRef =CFBundleCopyResourceURL(mainBundle, 
                                                 (CFStringRef) @"1 Marble", CFSTR ("aif"), NULL); //Sound Stuff
        
        UInt32 soundID;
        AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
        AudioServicesPlaySystemSound(soundID);
        
        [[records objectAtIndex:pageControl.currentPage] setValue:marbleNumber forKey:@"marbles"]; //Set Marble Value
        [self checkPrizeReached];
        NSError *error;
        [_managedObjectContext save:&error]; //Save 
        
        [UIView beginAnimations:nil context:nil]; //Move To Start Position With Animation
        [UIView setAnimationDuration:0.5];
        plusone.center = CGPointMake(36, 46);
        [UIView commitAnimations];
        marblebeingdragged = NO;
    } else
    {
        marblebeingdragged = YES;
    }
Please Note That The Code Is Cutoff, and touchesEnded is repeated with UIImageView changes.

This has only started when I began working with iOS 5. The images drag fine in the iOS 4.3 Simulator. Is there something wrong?

Thanks
You can't judge ANYTHING by the performance of the simulator. Test things like animation code on the device, early and often.

The simulator runs in native Intel machine code that is tens of times faster than the processor in even an iPad 2, and has hundreds of times more memory. The performance characteristics of the simulator are NOTHING like that of a real device.

Also, pick the base device you support, and be sure to test on that.

The iPhone 3G is dramatically slower than the 3Gs. Apple has dropped support of the 3G for iOS 5. I would suggest doing the same. It's just too slow for recent animation tricks to work slowly. The 3Gs, will a little slower than the 4 and 4s, is reasonable.

Are you saying that your software is much slower under iOS 5 on a device than it is in 4.x on the same device? That's a different story.

I didn't really follow your code. It seems odd to have your touchesMoved method call touchesBegan.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Old 11-29-2011, 07:59 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 9
ahan.tm is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
You can't judge ANYTHING by the performance of the simulator. Test things like animation code on the device, early and often.

The simulator runs in native Intel machine code that is tens of times faster than the processor in even an iPad 2, and has hundreds of times more memory. The performance characteristics of the simulator are NOTHING like that of a real device.

Also, pick the base device you support, and be sure to test on that.

The iPhone 3G is dramatically slower than the 3Gs. Apple has dropped support of the 3G for iOS 5. I would suggest doing the same. It's just too slow for recent animation tricks to work slowly. The 3Gs, will a little slower than the 4 and 4s, is reasonable.

Are you saying that your software is much slower under iOS 5 on a device than it is in 4.x on the same device? That's a different story.

I didn't really follow your code. It seems odd to have your touchesMoved method call touchesBegan.
Also, When I test on my device(iPhone 4S & iOS 5.0.1) the same thing occurs. Should I be using a UIPanGestureRecognizer?

My old 3GS would run the code perfectly fine until I updated to iOS 5..
ahan.tm is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, uiimageview, uiimageview interaction

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 406
16 members and 390 guests
AppsBlogger, chiataytuday, Clouds, David-T, dedeys78, Duncan C, e2applets, EvilElf, iekei, ipodphone, leostc, LunarMoon, Murphy, sacha1996, Sami Gh, teebee74
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,912
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:40 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0