【问题标题】:Slide Out Navigation not working when I use revealToggle: method (SWRevealViewController Class)使用revealToggle时滑出导航不起作用:方法(SWRevealViewController类)
【发布时间】:2014-10-08 09:15:54
【问题描述】:

我已经在我的项目中成功实现了 SWRevealViewController 类。

https://github.com/John-Lluch/SWRevealViewController

但是当我使用revealToggle: 方法作为我的左栏按钮项操作时,它会显示一个完整的黑屏。视图是完全黑色的。 但是当我使用 rightRevealToggle: 方法时,视图加载正常。

我包括 AppDelegate.h、AppDelegate.m 和 Main view 的代码。

滑出视图现在是一个空视图。只是背景颜色改变了。

检查一下,让我知道哪里出了问题。

这是项目在模拟器中的截图

http://i57.tinypic.com/mljpe9.png

AppDelegate.h

//  AppDelegate.h
//  IndianBloodBank
//
//  Created by Roshith Balendran on 8/5/14.
//  Copyright (c) 2014 Olympus. All rights reserved.
//


#import <UIKit/UIKit.h>

@class SWRevealViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) SWRevealViewController *splitMenu;

@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;

- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;


@end

AppDelegate.m

//  AppDelegate.m
//  IndianBloodBank
//
//  Created by Roshith Balendran on 8/5/14.
//  Copyright (c) 2014 Olympus. All rights reserved.
//

#import "AppDelegate.h"
#import "SWRevealViewController.h"
#import "HomePageViewController.h"
#import "SlideOutMenuViewController.h"
#import "SearchViewController.h"
#import "SearchViewController.h"
#import "AboutUsViewController.h"
#import "SponsorsViewController.h"
#import "HowToDonateViewController.h"
#import "EmergencyViewController.h"

@interface AppDelegate()<SWRevealViewControllerDelegate>

@end

@implementation AppDelegate

@synthesize splitMenu,window;

@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    self.window = window;

    HomePageViewController *HPVC = [[HomePageViewController alloc]init];

    SlideOutMenuViewController *SOMVC = SOMVC = [[SlideOutMenuViewController alloc]init];




    UINavigationController *frontNavigationController = [[UINavigationController alloc]initWithRootViewController:HPVC];
    UINavigationController *rearNavigationController = [[UINavigationController alloc]initWithRootViewController:SOMVC];

    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.125 green:0.122 blue:0.133 alpha:1]];

    SWRevealViewController *revealController= [[SWRevealViewController alloc]initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];

    revealController.rearViewRevealWidth = 120;
    revealController.rearViewRevealOverdraw = 120;
    revealController.bounceBackOnOverdraw = NO;
    revealController.stableDragOnOverdraw = YES;
    [revealController setFrontViewPosition:FrontViewPositionLeft];

    revealController.delegate=self;
    revealController.rightViewController = SOMVC;
    self.splitMenu = revealController;

    self.window.rootViewController = self.splitMenu;

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;


}

HomePageViewController.m

//  HomePageViewController.m
//  IndianBloodBank
//
//  Created by Roshith Balendran on 8/5/14.
//  Copyright (c) 2014 Olympus. All rights reserved.
//

#import "HomePageViewController.h"
#import "SWRevealViewController.h"
#import "AboutUsViewController.h"
#import "SponsorsViewController.h"
#import "HowToDonateViewController.h"
#import "SearchViewController.h"

@interface HomePageViewController ()

@end

@implementation HomePageViewController

@synthesize btn1SearchBlood,btn2DonateNow;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    self.navigationController.navigationBar.translucent=NO;

    SWRevealViewController *revealViewController = [self revealViewController];

    [revealViewController panGestureRecognizer];
    [revealViewController tapGestureRecognizer];

    UIView* MenuButtonView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 25, 20)];

    UIButton* MenuButton=[UIButton buttonWithType:UIButtonTypeSystem];
    MenuButton.frame=MenuButtonView.frame;
    [MenuButton setImage:[UIImage imageNamed:@"v1_menu-icon"] forState:UIControlStateNormal];
    MenuButton.tintColor=[UIColor grayColor];
    MenuButton.autoresizesSubviews=YES;
    MenuButton.autoresizingMask=UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;
    [MenuButton addTarget:revealViewController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];
    [MenuButtonView addSubview:MenuButton];

    UIBarButtonItem *Menu=[[UIBarButtonItem alloc]initWithCustomView:MenuButtonView];

    self.navigationItem.leftBarButtonItem=Menu;


}

【问题讨论】:

  • 如果您从不接受答案。没有人愿意帮助你。
  • 什么..??!!!我什么时候说过,我不会接受帮助……???我完全被困住了,我正在寻求你的帮助......
  • 我不知道哪里出了问题,我正在等待一些有经验的人帮助我......我不明白,为什么你说我不会接受答案..! !!???
  • 对不起我的第一个问题。我忘了使用 initwithnibname。过了一段时间我才知道。我想,我接受了一个作为答案......而对于第二个问题,我根本没有得到任何答案......那个人让我重新提出我的问题......但到那时,我玩弄并修复了错误..我回答了这个问题,因为没有人回答...至于这篇文章,这是我的第三个问题
  • 这是我的错误,我不知道,我没有接受我第一个问题的答案。我刚刚发现我必须点击绿色的勾号图标才能接受答案......不会再发生这种情况,我没有射击和滑行。我真诚地向你们道歉……我应该做得比那更好……

标签: objective-c ios7 swrevealviewcontroller


【解决方案1】:

我找到了解决问题的方法...

我的教练帮我解决了这个问题。

这是修改后的代码。

感谢大家的帮助。

AppDelegate.h

//  AppDelegate.h
//  IndianBloodBank
//
//  Created by Roshith Balendran on 8/5/14.
//  Copyright (c) 2014 Olympus. All rights reserved.
//


#import <UIKit/UIKit.h>

@class SWRevealViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) SWRevealViewController *splitMenu;

@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;

- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;


@end

AppDelegate.m

//  AppDelegate.m
//  IndianBloodBank
//
//  Created by Roshith Balendran on 8/5/14.
//  Copyright (c) 2014 Olympus. All rights reserved.
//

#import "AppDelegate.h"
#import "SWRevealViewController.h"
#import "HomePageViewController.h"
#import "SlideOutMenuViewController.h"
#import "SearchViewController.h"
#import "SearchViewController.h"
#import "AboutUsViewController.h"
#import "SponsorsViewController.h"
#import "HowToDonateViewController.h"
#import "EmergencyViewController.h"

@interface AppDelegate()<SWRevealViewControllerDelegate>

@end

@implementation AppDelegate

@synthesize splitMenu,window;

@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

//    self.window = window;

    HomePageViewController *HPVC = [[HomePageViewController alloc]initWithNibName:@"HomePageViewController" bundle:nil];

    SlideOutMenuViewController *SOMVC ;

    SOMVC = [[SlideOutMenuViewController alloc]init];


    UINavigationController *frontNavigationController = [[UINavigationController alloc]initWithRootViewController:HPVC];

//    UINavigationController *rearNavigationController = [[UINavigationController alloc]initWithRootViewController:SOMVC];

    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.078 green:0.09 blue:0.078 alpha:1]];

    splitMenu= [[SWRevealViewController alloc]initWithRearViewController:SOMVC frontViewController:frontNavigationController];

    splitMenu.rearViewRevealWidth = 120;
    splitMenu.rearViewRevealOverdraw = 120;
    splitMenu.bounceBackOnOverdraw = NO;
    splitMenu.stableDragOnOverdraw = YES;
    [splitMenu setFrontViewPosition:FrontViewPositionLeft];

    splitMenu.delegate=self;
    splitMenu.rightViewController = SOMVC;


    self.window.rootViewController = splitMenu;

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;


}

HomePageViewController.m

//  HomePageViewController.m
//  IndianBloodBank
//
//  Created by Roshith Balendran on 8/5/14.
//  Copyright (c) 2014 Olympus. All rights reserved.
//

#import "HomePageViewController.h"
#import "SWRevealViewController.h"
#import "AboutUsViewController.h"
#import "SponsorsViewController.h"
#import "HowToDonateViewController.h"
#import "SearchViewController.h"

@interface HomePageViewController ()

@end

@implementation HomePageViewController
{
    SWRevealViewController *slideController;
}

@synthesize btn1SearchBlood,btn2DonateNow;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    self.navigationController.navigationBar.translucent=NO;

    slideController = [self revealViewController];

    //[revealViewController panGestureRecognizer];
   // [revealViewController tapGestureRecognizer];

    UIView* MenuButtonView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 25, 20)];

    UIButton* MenuButton=[UIButton buttonWithType:UIButtonTypeSystem];
    MenuButton.frame=MenuButtonView.frame;
    [MenuButton setImage:[UIImage imageNamed:@"v1_menu-icon"] forState:UIControlStateNormal];
    MenuButton.tintColor=[UIColor grayColor];
    MenuButton.autoresizesSubviews=YES;
    MenuButton.autoresizingMask=UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;
    [MenuButton addTarget:slideController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];
    [MenuButtonView addSubview:MenuButton];

    UIBarButtonItem *Menu=[[UIBarButtonItem alloc]initWithCustomView:MenuButtonView];

    self.navigationItem.leftBarButtonItem=Menu;


}

【讨论】:

    猜你喜欢
    • 2016-12-07
    • 2016-05-12
    • 1970-01-01
    • 2015-10-04
    • 1970-01-01
    • 2014-04-09
    • 2020-11-13
    • 2014-10-08
    • 1970-01-01
    相关资源
    最近更新 更多