gpt4 book ai didi

ios - 在 ios 中以横向模式显示 iPad 的侧边栏,如 facebook

转载 作者:行者123 更新时间:2023-11-28 22:11:24 25 4
gpt4 key购买 nike

我有一个 iPad 应用程序,我想在其中实现侧边栏功能,就像我们在 facebook 应用程序中一样。

我正在使用这个 Demo为此。

有了这个,我已经成功地实现了边栏功能并且它运行良好,但是我的第一个 View 并没有很好地显示我。

下面是截图。

enter image description here

正如您从屏幕截图中看到的那样,有一个黑色背景,当应用程序启动时,我的整个 View 并未全屏显示。

它应该像下面这样。

enter image description here

同样在单击按钮时,侧 View 显示如下。

enter image description here

它应该很小,因为我采用了宽度 = 300 和高度 = 768 的 View 大小。

但它显示的比那个大。

这是我在 appdelegate 中更改的代码。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

[self createEditableCopyOfDatabaseIfNeeded];

// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:self.viewController];

SlidingViewController *slidingView = [[SlidingViewController alloc]initWithNibName:@"SlidingViewController" bundle:nil];

self.slideMenuController = [[SlideMenuController alloc] initWithCenterViewController:navController];
self.slideMenuController.leftViewController = slidingView;

self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}

- (IBAction)sideBarPressed:(id)sender
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.slideMenuController.position == TKSlidePositionCenter) {
[appDelegate.slideMenuController presentLeftViewControllerAnimated:YES];
} else {
[appDelegate.slideMenuController presentCenterViewControllerAnimated:YES];
}
}

我希望我的 iPad 仅在横向模式下使用它。

请告诉我这里有什么问题?

我被困在这里很长一段时间了。

我们将不胜感激。

提前致谢。

最佳答案

所以你需要使用 UISplitViewController 更好

 //in app delegate do like this
//in appDelegate.h file
#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, retain) UISplitViewController *splitViewCOntroller;
@end


//in appDelegate.m file
#import "AppDelegate.h"
#import "SplitMasterViewController.h" //create a UITableviewController
#import "SplitViewDetailController.h" //create a UIViewController

@implementation AppDelegate
@synthesize splitViewCOntroller = _splitViewCOntroller;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
SplitMasterViewController *masterController = [[SplitMasterViewController alloc]initWithNibName:@"SplitMasterViewController" bundle:nil]; //this is the master menu controller

UINavigationController *masterNavController = [[UINavigationController alloc]initWithRootViewController:masterController];

SplitViewDetailController *detailViewController = [[SplitViewDetailController alloc]initWithNibName:@"SplitViewDetailController" bundle:nil]; //this is the master detail controller


UINavigationController *detailNavController = [[UINavigationController alloc]initWithRootViewController:detailViewController];
masterController.detailViewController = detailViewController;

_splitViewCOntroller = [[UISplitViewController alloc]init]; //initilise split controller
_splitViewCOntroller.delegate = detailViewController; //set the delegate to detail controller
_splitViewCOntroller.viewControllers = [NSArray arrayWithObjects:masterNavController,detailNavController, nil]; //set the splitview controller
self.window.rootViewController = _splitViewCOntroller; //finally your splitviewcontroller as the root view controller
[self.window makeKeyAndVisible];

return YES;
}


//in SplitMasterViewController.h this must be a table that contains your side bar menu items
#import "ViewController.h" //comment this if it shows any error
#import "SplitViewDetailController.h"

@interface SplitMasterViewController : UITableViewController<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, retain) SplitViewDetailController *detailViewController; //to get the detailview from masterMenu controller
@property (nonatomic, retain) NSArray *Names;

@end

// in SplitMasterViewController.m file
#import "SplitMasterViewController.h"
#import "SplitViewDetailController.h"


@interface SplitMasterViewController ()

@end

@implementation SplitMasterViewController

@synthesize Names;
@synthesize detailViewController;


- (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.
Names = [[NSArray alloc] initWithObjects:@"apple", @"banana",
@"mango", @"grapes", nil];

[self.tableView selectRowAtIndexPath:
[NSIndexPath indexPathForRow:0 inSection:0]
animated:NO
scrollPosition:UITableViewScrollPositionMiddle];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [Names count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}

// [self configureCell:cell atIndexPath:indexPath];

cell.textLabel.text = [Names objectAtIndex:indexPath.row];
return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SplitViewDetailController *detailController = self.detailViewController;
detailController.myLabel.text = [Names objectAtIndex:indexPath.row]; //set the name from the array
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end


//in SplitViewDetailController.h
#import "ViewController.h"

@interface SplitViewDetailController : UIViewController<UISplitViewControllerDelegate>
@property (strong, nonatomic) id detailItem;
@property (strong, nonatomic) IBOutlet UILabel *myLabel;
@property (nonatomic, retain) UIBarButtonItem *leftBarButtonItem; //to show a button on left side

@end

//in SplitViewDetailController.m

#import "SplitViewDetailController.h"

@interface SplitViewDetailController ()
{
UIPopoverController *masterPopoverController;
}

@end

@implementation SplitViewDetailController

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

- (void)viewDidLoad
{
[super viewDidLoad];
// _leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Menu" style:UIBarButtonItemStyleBordered target:self action:nil];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}


//these are the call back to detail view controller to hide or show the button
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
_leftBarButtonItem = barButtonItem;
_leftBarButtonItem.style = UIBarButtonItemStyleBordered;
_leftBarButtonItem.title = @"Menu";
[self.navigationItem setLeftBarButtonItem:_leftBarButtonItem animated:YES];
}

// Called when the view is shown again in the split view, invalidating the button
- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
}

@end

关于ios - 在 ios 中以横向模式显示 iPad 的侧边栏,如 facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22834254/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com