Muh*_*ikh 0 iphone ios7 xcode5
我正在创建一个小的滑出菜单,而不使用任何库.通过使用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;
}
Run Code Online (Sandbox Code Playgroud)
这就是我在IBAction中所称的方式
- (IBAction)menuAction:(id)sender {
[self showMenu:YES];
}
Run Code Online (Sandbox Code Playgroud)
我尝试过不同类型的if语句,但我无法将其关闭.
请帮忙.
提前致谢
我误解了动态行为.好的,我建议使用BOOL.声明BOOL
BOOL isMenuVisible;
Run Code Online (Sandbox Code Playgroud)
然后在IBAction中使用它
- (IBAction)menuAction:(id)sender {
if(isMenuVisible == NO){
self.isMenuVisible = YES;
[self showMenu:self.isMenuVisible];
}else{
self.isMenuVisible = NO;
[self showMenu:self.isMenuVisible];
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
99 次 |
| 最近记录: |