我正在使用JTRevealSideBarDemoV2来实现像facebook和Path应用程序这样的侧面板。我已经在各种意义上配置它,只是想在这个库中添加一个功能。我想要的是在这个库中应用手势识别器控件,就像facebook一样。有人可以帮忙吗?
下载此库的链接是: - https://www.cocoacontrols.com/controls/jtrevealsidebar
谢谢!
@wattson: - 这是我为实现Gesture Recognizer而添加的代码。 BBut表现得非常不正常。如果您已经下载了JTRevealSideBarDemoV2的代码,那么您可以分析我为其编写的代码。
代码是:
(void)setUpGestures{
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc]
initWithTarget:self action:@selector(movePanel:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[self.view addGestureRecognizer:panRecognizer];
}
-(void)movePanel:(id)sender {
[[[(UITapGestureRecognizer*)sender view] layer] removeAllAnimations];
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender
translationInView:self.view];
CGPoint velocity = [(UIPanGestureRecognizer*)sender velocityInView:[sender view]];
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {
//UIView *childView = nil;
if(velocity.x > 0) {
if (!JTRevealedStateRight) {
[self revealLeftSidebar:(UIPanGestureRecognizer *)sender];
}
} else {
if (!JTRevealedStateLeft) {
[self revealRightSidebar:(UIPanGestureRecognizer *)sender];
}
}
// Make sure the view you're working with is front and center.
//[self.view sendSubviewToBack:];
[[sender view] bringSubviewToFront:[(UIPanGestureRecognizer*)sender view]];
}
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
if(velocity.x > 0) {
// NSLog(@"gesture went right");
} else {
// NSLog(@"gesture went left");
}
if (!_showPanel) {
[self revealLeftSidebar:(UIPanGestureRecognizer *)sender];
} else {
if (JTRevealedStateLeft) {
[self revealRightSidebar:(UIPanGestureRecognizer *)sender];
} else if (JTRevealedStateRight) {
[self revealLeftSidebar:(UIPanGestureRecognizer *)sender];
}
}
}
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateChanged) {
if(velocity.x > 0) {
// NSLog(@"gesture went right");
} else {
// NSLog(@"gesture went left");
}
// Are you more than halfway? If so, show the panel when done dragging by setting this
value to YES (1).
_showPanel = abs([sender view].center.x - self.view.frame.size.width/2) >
self.view.frame.size.width/2;
// Allow dragging only in x-coordinates by only updating the x-coordinate with
translation position.
[sender view].center = CGPointMake([sender view].center.x + translatedPoint.x, [sender
view].center.y);
[(UIPanGestureRecognizer*)sender setTranslation:CGPointMake(0,0) inView:self.view];
// If you needed to check for a change in direction, you could use this code to do so.
if(velocity.x*_preVelocity.x + velocity.y*_preVelocity.y > 0) {
// NSLog(@"same direction");
} else {
// NSLog(@"opposite direction");
}
_preVelocity = velocity;
}
}