Bien d'abord, si votre nouveau je suggère d'obtenir un livre. Le mien est Début iPhone 4 Développement
par Dave Mark, Jack Nutting, et Jeff LaMarche (Apress). Cela m'a évité de perdre beaucoup de temps et de commencer. Aussi, il peut y avoir de meilleurs livres adaptés à ce dont vous avez besoin, mais celui-ci a un assez bon chapitre sur Taps, Touches et Gestes ... appelé 15: Taps, Touches et Gestes.
de toute façon l'essentiel Heres:
const UIImageView * viewBeingDragged = nil;
// in your rootController
// (lets say a UIViewController with one UIImageView)
//
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint touchPoint = [[touches anyObject] locationInView:self.view];
//our image views are direct decendents of our main view
//the following method returns the farthest decendent from the target
//in the point, so make sure you dont have any intersecting subviews!
//pretty sure you dont need event
//
UIView *v = [self.view hitTest:touchPoint event:nil];
NSAssert([v isMemberOfClass:[UIImageView class]], @"Not an image view?!?!?"]);
viewBeingDragged = (UIImageView *)v;
[v removeFromSuperview];
// or just gray it out...
[self.view.superview.superview addSubview:v];
//should be your splitViewController, if not get from AppDelegate
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
viewBeingDragged.center =
[[touches anyObject] locationInView:SplitControllerView];
if (viewBeingDragged.frame intersects with detailViewController.view.frame)
{
//visual cue that landing zone is set
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
// last check if view still intersects
// if so move underlieing data from left to right
// redraw left view
// remove viewBeingDragged from superview
// add viewBeingDragged to
viewBeingDragged = nil;
}
vous pouvez également mettre en œuvre touchesCanceled
Je nai testé cette méthode si les choses inattendues peuvent arriver.
Aussi, UIView a les mêmes méthodes tactiles, donc si vous voulez créer votre propre contrôleur de vue/vue personnalisé pour le rendre plus ... "extensible".