Xcode Xib - iOS模拟器的黑色边框右侧和底部
问题描述:
我正在使用Xcode 8.2.1,每当将视图设置为较小的设备时,我都会在设备的右侧和底部获取这些背面边框XIB文件。每当我选择iPhone 7 Plus,然后在iPhone 7上运行时,界面的一部分被推离屏幕的右侧和底部,也存在这样的问题。目前所有东西都在Objective-C中编码。Xcode Xib - iOS模拟器的黑色边框右侧和底部
更新:
主屏幕。
代码:
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;
}
}
答
具有 “设置约束到处可以” 可能不是你想要的。看起来你已经设置了明确的宽度和高度。删除所有当前的约束条件,而是设置值为0的顶部,底部,前导和尾部约束,并取消选中“约束到边距”(如果希望tableview填充视图)。
编辑:
在聊天经过一番讨论后,我意识到,这已经无关自动版式的限制。相反,由于您正在为主窗口使用XIB,因此它将根据XIB中设置的大小显式调整大小。所有你需要做的正确的大小是告诉它什么是你的屏幕的大小。在applicationDidFinishLaunching:
的任何地方,只需添加[window setFrame:UIScreen.mainScreen.bounds];
,它将调整到设备屏幕的大小。
当您的视图小于设备的屏幕时会发生这种情况。您应该启用自动布局并添加限制以适合任何设备。 – Calc91
@ Calc91我已经启用了自动布局,并且在任何地方都可以设置约束条件。 – Number1