Non è necessario trovare una soluzione alternativa di trascinamento della selezione. Un UIScrollView può farlo senza alcuna perdita di prestazioni causata dall'ascolto di tocchi.

@interface PulldownView : UIScrollView
@end
@implementation PulldownView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (!self) {
return self;
}
self.pagingEnabled = YES;
self.bounces = NO;
self.showsVerticalScrollIndicator = NO;
[self setBackgroundColor:[UIColor clearColor]];
double pixelsOutside = 20;// How many pixels left outside.
self.contentSize = CGSizeMake(320, frame.size.height * 2 - pixelsOutside);
// redArea is the draggable area in red.
UIView *redArea = [[UIView alloc] initWithFrame:frame];
redArea.backgroundColor = [UIColor redColor];
[self addSubview:redArea];
return self;
}
// What this method does is to make sure that the user can only drag the view from inside the area in red.
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if (point.y > height)
{
// Leaving useless touches to the views under it.
return nil;
}
return [super hitTest:point withEvent:event];
}
@end
Come si usa:
1. Inizializza un'istanza di PulldownView.
2. Aggiungere qualsiasi contenuto che si desidera visualizzare all'istanza usando [addSubview:].
3. Nascondere l'area in rosso.
[pulldownView setContentOffset:CGPointMake(0, heightOfTheView - pixelsOutside)];
Questo è un semplice esempio. È possibile aggiungere qualsiasi funzionalità ad esso come aggiungere una barra dei pulsanti titolata nella parte inferiore dell'area trascinabile per implementare il click-n-drop o aggiungere un metodo all'interfaccia per riposizionarlo dal chiamante.
fonte
2012-04-28 16:04:21
Will - (void) pan: (UIPanGestureRecognizer *) il gesto esegue il lavoro? – Alby
Sì, ma devi essere più attento mentre lo usi ...come è necessario definire il controllo corretto e altre cose ... Va bene anche ... ma se stai usando Touchesbegin e TouchesEnded ... allora puoi semplicemente dare IBOutlets in Interface Builder ... – DShah