Actually I'm having a scroll-view. In that I'm using 30-buttons. what's my requirement is I need to rearrange the buttons. Like, when i touched any button it should be selected with our touch. and where ever we move in the scroll-view it should move along with our touch. after i ended the touch, the buttons should be swapped. Can any one help me regarding this.........
A:
You can do this behavior but there a lot of work. You need next:
1. Create UIControl subclass that will be your buttons.
2. Override all touches* methods there.
3. Implement there support of standard uicontrol behavior + moving behavior.
#pragma mark -
#pragma mark Touches delegate methods
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
[self performSelector:@selector(delayedTouchBeging:) withObject:touch afterDelay:0.15];
[super touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ( dragging ) {
// move your view in new position here
} else {
[super touchesMoved:touches withEvent:event];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if ( dragging ) {
// Do other stuff if you need
} else {
[super touchesEnded:touches withEvent:event];
}
dragging = NO;
[NSObject cancelPreviousPerformRequestsWithTarget:self];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesEnded:touches withEvent:event];
}
- (void) delayedTouchBeging:(UITouch*) touch {
dragging = YES;
[self cancelTrackingWithEvent:nil];
// Do here stuff about begin moving (animation, etc)
}
Skie
2010-04-26 13:19:42
A:
You may want to look into how they do the "Launcher" code as a part of the three20 code catalog that's available for free. They do exactly something like this (and mimicks the iPhone apps view where you can move apps around or delete them).
iWasRobbed
2010-04-30 03:36:13