我正在创建一个小滑出菜单而不使用任何库。通过使用UIDynamics,我可以通过单击IBAction按钮来滑动打开菜单。打开/关闭菜单条件
我想问一下,如何通过点击相同的btn来关闭菜单。点击另一个btn可以关闭菜单,例如菜单中的“关闭”btn,但我也想通过点击打开它的相同菜单btn来关闭它。
这是显示菜单
-(BOOL)showMenu:(BOOL)yesNO{
//cleaning the screen of any behaviors
[self.animator removeAllBehaviors];
//animation will go from side to side
CGFloat graxityDirectionX = (yesNO) ? 0.1 : -1.0;
//detecting the collision of the menu
CGFloat collision = (yesNO) ? menuWidth : -menuWidth;
//insitating the gravity and telling it work on the menu
UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:@[self.menuView]];
gravity.gravityDirection = CGVectorMake(graxityDirectionX, 0);
//adding the animation
[self.animator addBehavior:gravity];
//instaniating the collision and telling the menu were to stop
UICollisionBehavior *collisionMenu = [[UICollisionBehavior alloc] initWithItems:@[self.menuView]];
//telling the menu where and what to collide it by using an invisible line
[collisionMenu addBoundaryWithIdentifier:@"menuBoundry" fromPoint:CGPointMake(collision, 580) toPoint:CGPointMake(collision, 0)];
//adding the collision
[self.animator addBehavior:collisionMenu];
//setting the bounce
UIDynamicItemBehavior *menuBounce = [[UIDynamicItemBehavior alloc]initWithItems:@[self.menuView]];
menuBounce.elasticity = 0;
[self.animator addBehavior:menuBounce];
return YES;
}
的功能,这是我怎么在IBAction为
- (IBAction)menuAction:(id)sender {
[self showMenu:YES];
}
我尝试了多种不同类型的if语句调用它,但我不能让它关闭。
请帮忙。
在此先感谢
您是否尝试过使用存储的菜单是否显示或不显示状态的变量?或者,您是否可以返回您可以致电的信息? – Abizern 2014-10-29 08:35:22
对于菜单状态的状态你是什么意思? 使用-menuWidth和动画在中间滑动,菜单从视图中隐藏。 – 2014-10-29 09:57:17
已尝试使用按钮的“selected”状态进行操作? – holex 2014-10-29 11:19:04