No es necesario encontrar una solución de arrastrar y soltar. Un UIScrollView puede hacerlo sin ninguna pérdida de rendimiento al escuchar toques.
@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
Modo de empleo: 1. Inicializar
una instancia de PulldownView.
2. Agregue cualquier contenido que desee mostrar a la instancia utilizando [addSubview:].
3. Oculta el área en rojo.
[pulldownView setContentOffset:CGPointMake(0, heightOfTheView - pixelsOutside)];
Este es un ejemplo simple. Puede agregarle funciones como agregar una barra de botones titulada en la parte inferior del área que se puede arrastrar para implementar click-n-drop, o agregar algún método a la interfaz para reposicionarlo por la persona que llama.
Will - (void) pan: (UIPanGestureRecognizer *) ¿gesto hace el trabajo? – Alby
Sí, pero debes ser más cuidadoso mientras lo usas ...ya que necesita definir el control adecuado y otras cosas ... También es bueno ... pero si usa Touchesbegin y TouchesEnded ... entonces simplemente puede dar IBOutlets en Interface Builder ... – DShah