我正在iOS中像Facebook这样的幻灯片菜单做一个简单的应用程序我从这个链接中提供的教程一步一步地进行处理http://www.raywenderlich.com/32054/how-to-create-a-slide-out-navigation-like-facebook-and-path 。当我单击按钮时,我正在进行右侧面板滑动,但是当我再次调用我的主视图时,它正在发生但是应用程序崩溃可以帮助我摆脱这个问题
#define RIGHT_PANEL 2
#define CENTRAL_TAG 1
#define SLIDE_TIMING .25
#define PANEL_WIDTH 60
@interface MainViewController ()<CenterViewControllerDelegate>
@property(nonatomic,strong)CentralViewController *centralView;
@property(nonatomic,strong)RightViewController *RightView;
@property (nonatomic, assign) BOOL showingRightPanel;
-(UIView*)getright;
-(UIView*)resetmainView;
@end
@implementation MainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.centralView = [[CentralViewController alloc] initWithNibName:@"CentralViewController" bundle:nil];
self.centralView.view.tag = CENTRAL_TAG;
self.centralView.delegate=self;
[self.view addSubview:self.centralView.view];
[self addChildViewController:_centralView];
[_centralView didMoveToParentViewController:self];
}
-(UIView*)getright
{
if(_RightView==Nil)
{
self.RightView=[[RightViewController alloc]initWithNibName:@"RightViewController" bundle:Nil];
self.RightView.view.tag=RIGHT_PANEL;
self.RightView.delegate=self;
[self.view addSubview:self.RightView.view];
[self addChildViewController:self.RightView];
[_RightView didMoveToParentViewController:self];
_RightView.view.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}
self.showingRightPanel=YES;
UIView *view=self.RightView.view;
return view;
}
-(void)MovetoOriginal
{
[UIView animateWithDuration:SLIDE_TIMING delay:0 options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
_centralView.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}
completion:^(BOOL finished) {
if (finished) {
[self resetmainView];
}
}];}
-(void)rightpanelmove
{
UIView *child=[self getright];
[self.view sendSubviewToBack:child];
[UIView animateWithDuration:SLIDE_TIMING delay:0 options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
_centralView.view.frame = CGRectMake(-self.view.frame.size.width + PANEL_WIDTH, 0, self.view.frame.size.width, self.view.frame.size.height);
}
completion:^(BOOL finished) {
if (finished) {
_centralView.rightbutton.tag = 1;
}
}];
}
-(UIView*)resetmainView
{
if(_RightView!=Nil)
{
[self.RightView.view removeFromSuperview];
self.RightView=Nil;
_centralView.rightbutton.tag=0;
self.showingRightPanel=NO;
}
这是我调用事件的主要控制代码
这个是按钮动作代码
- (IBAction)btnright:(id)sender {
UIButton *button = sender;
switch (button.tag) {
case 0: {
[_delegate rightpanelmove];
break;
}
case 1: {
[_delegate MovetoOriginal];
break;
}
default:
break;
}}
答案 0 :(得分:0)
-(UIView*)resetmainView
{
if(_RightView!=Nil)
{
[self.RightView.view removeFromSuperview];
self.RightView=Nil;
_centralView.rightbutton.tag=0;
self.showingRightPanel=NO;
}
UIView *view=self.centralView.view;
return view;
}
这就是我现在错过的工作!!!!