2017-03-01 137 views
0

我正在使用Xcode 8.2.1,每当将视图设置为较小的设备时,我都会在设备的右侧和底部获取这些背面边框XIB文件。每当我选择iPhone 7 Plus,然后在iPhone 7上运行时,界面的一部分被推离屏幕的右侧和底部,也存在这样的问题。目前所有东西都在Objective-C中编码。Xcode Xib - iOS模拟器的黑色边框右侧和底部

Device with black borders

更新:

主屏幕。

View Stack View Windows

代码:

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

当您的视图小于设备的屏幕时会发生这种情况。您应该启用自动布局并添加限制以适合任何设备。 – Calc91

+0

@ Calc91我已经启用了自动布局,并且在任何地方都可以设置约束条件。 – Number1

回答

2

具有 “设置约束到处可以” 可能不是你想要的。看起来你已经设置了明确的宽度和高度。删除所有当前的约束条件,而是设置值为0的顶部,底部,前导和尾部约束,并取消选中“约束到边距”(如果希望tableview填充视图)。

Add Constraints

编辑:

在聊天经过一番讨论后,我意识到,这已经无关自动版式的限制。相反,由于您正在为主窗口使用XIB,因此它将根据XIB中设置的大小显式调整大小。所有你需要做的正确的大小是告诉它什么是你的屏幕的大小。在applicationDidFinishLaunching:的任何地方,只需添加[window setFrame:UIScreen.mainScreen.bounds];,它将调整到设备屏幕的大小。

+0

对于这些视图,所有设置约束都变灰。当我说我为上面的所有内容设置了约束时,这是为了不同的视图,它似乎不属于这个1,因为它在后面的堆栈中。 – Number1

+0

好的,我在你的更新中看到你的视图不在视图控制器内,所以是像我说的那样添加约束是行不通的。你如何显示有问题的视图(不能正确缩放的视图)?我在你的故事板截图中没有看到任何细节或关系。你是否实例化并手动预置它?代码的样子是什么? –

+0

我没有使用segues或关系,因为我使用xib而不是storyboard。从我的理解我相信我正在实例化的意见。 – Number1