Xcode Xib - iOS 模拟器右侧和底部的黑色边框
Xcode Xib - Black border right and bottom of iOS Simulator
我正在使用 Xcode 8.2.1,每当我在 XIB 文件中将视图设置为较小的设备时,我就会在设备的右侧和底部看到这些后边框。还有一个问题,每当我 select iPhone 7 Plus 然后 运行 在 iPhone 7 上时,界面的一部分被推离屏幕的右侧和底部.目前一切都在 Objective-C.
中编码
更新:
主屏幕。
代码:
RootViewController
#import "RootViewController.h"
#import "AppDelegate.h"
#import "DetailViewController.h"
- (void)viewDidLoad {
[super viewDidLoad];
if(CurrentLevel == 0) {
NSArray *tempArray = [[NSArray alloc] init];
self.tableDataSource = tempArray;
[tempArray release];
AppDelegate *AppDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
self.tableDataSource = (AppDelegate.data)[@"Rows"];
self.navigationItem.title = @"Title";
}
else
self.navigationItem.title = CurrentTitle;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *dictionary = (self.tableDataSource)[indexPath.row];
NSArray *Children = dictionary[@"Children"];
if(Children.count == 0) {
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:dvController animated:YES];
dvController.CurrentTitle = dictionary[@"Title"];
[dvController release];
}
else {
RootViewController *rvController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];
rvController.CurrentLevel += 1;
rvController.CurrentTitle = dictionary[@"Title"];
[self.navigationController pushViewController:rvController animated:YES];
rvController.tableDataSource = Children;
[rvController release];
}
}
AppDelegate
#import "AppDelegate.h"
#import "RootViewController.h"
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSString *Path = [NSBundle mainBundle].bundlePath;
NSString *DataPath = [Path stringByAppendingPathComponent:@"Master.plist"];
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
self.data = tempDict;
[tempDict release];
[window setRootViewController:navigationController];
[window makeKeyAndVisible];
}
DetailViewController
#import "DetailViewController.h"
#import "AppDelegate.h"
@implementation DetailViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
拥有"constraints set everywhere you can"可能不是您想要的。看起来您已经设置了明确的宽度和高度。删除所有当前约束,而是设置值为 0 的顶部、底部、前导和尾随约束,并取消选中 'constrain to margins'(如果您希望表视图填充视图)。
编辑:
经过聊天讨论,我意识到这与 AutoLayout 约束无关。相反,由于您正在为您的主要 window 使用 XIB,因此它的大小被明确地调整为 XIB 中设置的大小。要让它的尺寸正确,您需要做的就是告诉它您的屏幕尺寸是多少。 applicationDidFinishLaunching:
中的任意位置,只需添加 [window setFrame:UIScreen.mainScreen.bounds];
,它将调整为设备屏幕的大小。
我正在使用 Xcode 8.2.1,每当我在 XIB 文件中将视图设置为较小的设备时,我就会在设备的右侧和底部看到这些后边框。还有一个问题,每当我 select iPhone 7 Plus 然后 运行 在 iPhone 7 上时,界面的一部分被推离屏幕的右侧和底部.目前一切都在 Objective-C.
中编码更新:
主屏幕。
代码:
RootViewController
#import "RootViewController.h"
#import "AppDelegate.h"
#import "DetailViewController.h"
- (void)viewDidLoad {
[super viewDidLoad];
if(CurrentLevel == 0) {
NSArray *tempArray = [[NSArray alloc] init];
self.tableDataSource = tempArray;
[tempArray release];
AppDelegate *AppDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
self.tableDataSource = (AppDelegate.data)[@"Rows"];
self.navigationItem.title = @"Title";
}
else
self.navigationItem.title = CurrentTitle;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *dictionary = (self.tableDataSource)[indexPath.row];
NSArray *Children = dictionary[@"Children"];
if(Children.count == 0) {
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:dvController animated:YES];
dvController.CurrentTitle = dictionary[@"Title"];
[dvController release];
}
else {
RootViewController *rvController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];
rvController.CurrentLevel += 1;
rvController.CurrentTitle = dictionary[@"Title"];
[self.navigationController pushViewController:rvController animated:YES];
rvController.tableDataSource = Children;
[rvController release];
}
}
AppDelegate
#import "AppDelegate.h"
#import "RootViewController.h"
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSString *Path = [NSBundle mainBundle].bundlePath;
NSString *DataPath = [Path stringByAppendingPathComponent:@"Master.plist"];
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
self.data = tempDict;
[tempDict release];
[window setRootViewController:navigationController];
[window makeKeyAndVisible];
}
DetailViewController
#import "DetailViewController.h"
#import "AppDelegate.h"
@implementation DetailViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
拥有"constraints set everywhere you can"可能不是您想要的。看起来您已经设置了明确的宽度和高度。删除所有当前约束,而是设置值为 0 的顶部、底部、前导和尾随约束,并取消选中 'constrain to margins'(如果您希望表视图填充视图)。
编辑:
经过聊天讨论,我意识到这与 AutoLayout 约束无关。相反,由于您正在为您的主要 window 使用 XIB,因此它的大小被明确地调整为 XIB 中设置的大小。要让它的尺寸正确,您需要做的就是告诉它您的屏幕尺寸是多少。 applicationDidFinishLaunching:
中的任意位置,只需添加 [window setFrame:UIScreen.mainScreen.bounds];
,它将调整为设备屏幕的大小。