cocoa touch - Bug when moving a UIView horizontally -


i've created puzzle engine ipad (ios sdk 4.2)

i have puzzleviewcontroller controls uiview (rootview) holds smaller uiview (puzzleview) , twelve puzzle pieces (puzzlepieceview class extends uiimageview).

the ideia simple. puzzlepieces around puzzleview , picked , dragged puzzleview. when pieces picked double they're size , centered place finger touching. when they're dropped in right place stay put (they're removed rootview , added subviews puzzleview) if they're drop in wrong place return original position , size.

currently i'm overriding touches began/moved/ended/cancelled in puzzlepieceview class each puzzlepiece controls own movements.

here's do

#pragma mark uiresponder overriding  - (void)touchesbegan:(nsset *)touches withevent:(uievent *)event {     nslog(@"puzzlepiece touchesbegan");     if (!isdeployed) {         if (self.initialsize.width == 0 || self.initialsize.height ==0) { //if there still no initial size             self.initialsize = self.frame.size;         }         nslog(@"self.initiallocation.x %f %f", self.initiallocation.x, self.initiallocation.y);         if (self.initiallocation.x == 0. || self.initiallocation.y == 0.) { //if there still no initial location             self.initiallocation = self.center; //record initial location         }         uitouch *touch = [[event alltouches] anyobject];         self.center = [touch locationinview:self.superview]; //set center of view point finger touched         [self.superview bringsubviewtofront:self]; //the piece brings frontmostview visible , never behind other piece while moving     } }  - (void)touchesmoved:(nsset *)touches withevent:(uievent *)event {     nslog(@"puzzlepiece touchesmoved");     if (self.frame.size.width == self.initialsize.width) {         self.frame = cgrectmake(self.frame.origin.x, self.frame.origin.y, self.image.size.width, self.image.size.height);     }     if (!isdeployed) {         uitouch *touch = [[event alltouches] anyobject];         self.center = [touch locationinview:self.superview]; //set center of view point finger moved     } }  - (void)touchesended:(nsset *)touches withevent:(uievent *)event {     nslog(@"puzzlepiece touchesended");     if (!isdeployed) {         uitouch *touch = [[event alltouches] anyobject];         nslog(@"point %@ x%f y%f", self.puzzleview, [touch locationinview:self.puzzleview].x, [touch locationinview:self.puzzleview].y);         if (cgrectcontainspoint(self.dropzone,[touch locationinview:self.puzzleview])) {             [self removefromsuperview];             [self.puzzleviewcontroller addpiece:self];             self.center = self.finalcenter;             self.isdeployed = yes;         }         else {             [self restoretoinitialsize];             [self restoretoinitialposition];         }     }  }  - (void)touchescancelled:(nsset *)touches withevent:(uievent *)event {     nslog(@"puzzlepiece touchescancelled");     if (!isdeployed) {         [self restoretoinitialsize];         [self restoretoinitialposition];     }  }  #pragma mark - 

seemed pretty easy , was.

i've got 1 bug left. when try make horizontal move on puzzlepiece touch gets cancelled. happens when move started in fast way. if touch piece , wait moment (about second) pieces move perfectly. pieces move in vertical direction.

i've tried not changing puzzlepiece size when view first touched bu bug remains...

i found solution this. 1 of team-mates registered uiswipegesturerecognizer in rootview instead of specific subview swipegesture should recognized.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -