2014-10-30 66 views
-3

我有一個名爲「home」和一個名爲「菜單」的類與tableview,在家裏我創建一個按鈕來推菜單,當我點擊按鈕,我使框架移動並出現菜單但我不能點擊菜單中的表格視圖單元格,優先級是家庭。我該如何改變並完成這項工作?滑動菜單以編程方式

- (void)viewDidLoad { 

    [super viewDidLoad]; 
    menuViewController = [[ITMenuViewController alloc] init]; 
    menuViewController.view.frame = CGRectMake(0, 0, 0, 568); 
    [self.view addSubview:menuViewController.view]; 

    btn = [[UIButton alloc] init]; 

    btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [btn addTarget:self action:@selector(pushMenu) forControlEvents:UIControlEventTouchUpInside]; 
    [btn setTitle:@"push" forState:UIControlStateNormal]; 
    btn.frame = CGRectMake(40, 300, 240, 40); 
    [btn setBackgroundColor:[UIColor orangeColor]]; 
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
    btn.layer.cornerRadius = 2; 
    btn.tag = 1; 
    btn.clipsToBounds = YES; 
    //set other button properties here. 
    [self.view addSubview:btn]; 
} 

- (void)pushMenu { 

    if (menuViewController.view.frame.origin.x < 0 && btn.tag == 2) { 
     [UIView animateKeyframesWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{ 

     self.view.frame = CGRectMake(0, 0, 320, 568); 
     menuViewController.view.frame=CGRectMake(0, 0, 0, 568); 

     } completion:^(BOOL finished) { 
      btn.tag = 1; 
     }]; 
    } 

    if (menuViewController.view.frame.origin.x >= 0 && btn.tag == 1) 
    { 
     [UIView animateKeyframesWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 

      self.view.frame = CGRectMake(200, 0, 320, 568); 
      menuViewController.view.frame=CGRectMake(-self.view.frame.size.width + 0, 0, self.view.frame.size.width, 568); 
      [self.view.layer setCornerRadius:4]; 
      [self.view.layer setShadowColor:[UIColor blackColor].CGColor]; 
      [self.view.layer setShadowOpacity:0.8]; 
      [self.view.layer setShadowOffset:CGSizeMake(0.0f, 2.5f)];   
     } completion:^(BOOL finished) { 
      btn.tag = 2; 
     }]; 
    }} 
} 
+2

請顯示一些代碼。 – 2014-10-30 15:08:01

+0

好的,你現在可以檢查 – 2014-10-30 15:23:17

回答

0

檢查PPRevealSideViewController。它會幫助你爲你想要的https://github.com/ipup/PPRevealSideViewController

你可以在你的appdelegate添加您的主視圖控制器是這樣的:

HomeViewController *home = [[HomeViewController alloc initWithNibName:@"MainViewController" bundle:nil]; 
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:home]; 
_revealSideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:nav]; 

self.window.rootViewController = _revealSideViewController; 

,推動你的馬努 - 視圖 - 控制是這樣的:

MenuViewController *menu = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil ]; 
[self.revealSideViewController pushViewController:menu onDirection:PPRevealSideDirectionBottom animated:YES]; 

編輯

要添加PPRevealSideViewController爲您項目的子模塊轉到終端:

$ cd /path/to/MyApplication 
# If this is a new project, initialize git... 
$ git init 
$ git submodule add git://github.com/ipup/PPRevealSideViewController.git vendor/PPRevealSideViewController 
$ git submodule update --init --recursive 

- 在您的XCode項目中,從PPRevealSideViewController文件夾獲取PPRevealSideViewController.h和.m文件,並將它們拖到您的項目中。

- 將PPRevealSideViewController.h文件導入到PCH文件或AppDelegate文件中。

- 添加QuartzCore框架。

- 使用這個新的控制器開始!

+0

我嘗試使用但沒有找到文件#import ,如果我刪除了其他問題出現 – 2014-10-30 16:44:49

+0

你是如何安裝它的?通過cocoapods或作爲子模塊? – euthimis87 2014-10-30 16:47:19

+0

是的,我按照步驟,但錯誤仍然存​​在 – 2014-10-30 17:14:39