我想创建一个滑动"视图"。我希望能够把它从页面底部拉出来。我正在寻找的最接近的例子是倒数第二个护腕。我希望能够根据需要上下滑动此视图的位置。有人有什么好办法吗?我四处寻找例子,但从未见过这样的情况。
我认为您可以使用UIPanGestureRecognizer:
- (void)viewDidLoad
{
[super viewDidLoad];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @selector(panGestureRecognized:)];
[panRecognizer setDelegate:self];
[panRecognizer setCancelsTouchesInView: YES];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[self.handleImage addGestureRecognizer: panRecognizer];
firstX = [self.handleImage center].x;
firstY = [self.handleImage center].y;
}
-(void)panGestureRecognized:(id)sender {
[self.view bringSubviewToFront:[(UIPanGestureRecognizer*)sender view]];
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view];
UIPanGestureRecognizer* panRecognizer = (UIPanGestureRecognizer*)sender;
if ([panRecognizer state] == UIGestureRecognizerStateBegan) {
firstX = [[panRecognizer view] center].x;
firstY = [[panRecognizer view] center].y;
}
int nextPosition = firstY+translatedPoint.y;
if(nextPosition > MIN_Y && nextPosition < MAX_Y){
CGPoint certainPositin = CGPointMake([self.curtainView center].x,-(self.curtainView.frame.size.height) + (nextPosition - 17));
translatedPoint = CGPointMake(firstX,nextPosition);
[[panRecognizer view] setCenter:translatedPoint];
[self.curtainView setCenter:certainPositin];
}
if ([panRecognizer state] == UIGestureRecognizerStateEnded) {
//Gesture ended
}
}