iOS 10 iMessage app extension: how do i calculate

2019-01-21 23:10发布

I downloaded the Xcode 8 beta and was trying to play around with the iMessages app extension sdk but ran into an issue with their seemingly nonstandard nav bar height

when i transition into the app's expanded view, my image with the following frame CGRect(x: 0, y: 0, width: 100, height: 100) ends up partially hidden behind the nav bar. i would like it to appear below the nav bar.

i tried self.navigationController?.navigationBar.isTranslucent = false but it didn't work, which i guess makes sense since it's out of my app's scope to control.

has anyone played around with this yet? i want to avoid 2 things. simply guessing the appropriate height and moving away from a programmatic solution. compact expanded thanks for the help

8条回答
淡お忘
2楼-- · 2019-01-21 23:54

If you are like me and still find Auto Layout hard to use, then you can use the viewDidLayoutSubviews method to automatically adjust the view size. I have a table view with the same issue as you, so I used this simple method to change the table view's top side content inset:

-(void)viewDidLayoutSubviews {
    [self.tableView setContentInset:UIEdgeInsetsMake(self.topLayoutGuide.length, 0, 0, 0)];
}

So far it works fine (in both portrait and landscape) on all iDevices.

查看更多
别忘想泡老子
3楼-- · 2019-01-22 00:00

If you set the top layout guide as the top constraint, it works for MSMessagesAppViewController. But it will not work on UIViewControllers, because the layout guides are different.

Unless you really need to use a UIViewController class for some reason (example: MessagesAppViewControllers have trouble containing Obj C++ code), stick to MSMessagesAppViewController.

查看更多
登录 后发表回答