我已在项目中成功实现了SWRevealViewController类。
https://github.com/John-Lluch/SWRevealViewController
但是当我使用revealToggle:方法作为我的左栏按钮项目动作时,它会显示一个完整的黑屏。视图完全是黑色的。 但是当我使用rightRevealToggle:方法时,视图会正常加载。
我包括AppDelegate.h,AppDelegate.m和主视图的代码。
现在幻灯片视图是一个空视图。只是背景颜色改变了。
检查一下,让我知道出了什么问题。
以下是模拟器中项目的屏幕截图
http://i57.tinypic.com/mljpe9.png
// 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
// 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
// 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;
}
答案 0 :(得分:1)
我找到了解决问题的方法......
我的教练帮我解决了。
这是编辑过的代码。
感谢您的帮助。
// 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
// 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
// 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;
}