11-29-2011, 07:41 PM
#1 (permalink )
Registered Member
Join Date: Oct 2011
Posts: 9
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
11-29-2011, 07:49 PM
#2 (permalink )
Cocoa Junkie
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Quote:
Originally Posted by
ahan.tm
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.
11-29-2011, 07:59 PM
#3 (permalink )
Registered Member
Join Date: Oct 2011
Posts: 9
Quote:
Originally Posted by
Duncan C
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..
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» 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