Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

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:

- (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
Post edited by ahan.tm on

Replies

  • Duncan CDuncan C Posts: 8,032Tutorial Authors, Registered Users
    ahan.tm;391216 said:
    Hi,

    When I use the following code to manage image dragging and collisions, they are choppy and do not drag right:

    - (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

    mug

    Animated GIF created with Face Dancer, available for free in the app store.
  • ahan.tmahan.tm Posts: 10New Users
    Duncan C;391218 said:
    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..
Sign In or Register to comment.