Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 根据方向正确显示子视图控制器_Ios_Uiviewcontroller_Uiinterfaceorientation - Fatal编程技术网

Ios 根据方向正确显示子视图控制器

Ios 根据方向正确显示子视图控制器,ios,uiviewcontroller,uiinterfaceorientation,Ios,Uiviewcontroller,Uiinterfaceorientation,我正在尝试创建一个facebook组件(UIViewController的子类)来共享图片。现在可以在以下位置找到其状态的演示: 集成在ViewController中,我想这样使用它: _shareSheet = [[FBSharePictureViewController alloc] initWithImage:self.currentImage.image andDelegate:self]; // Create the instance [_shareSheet showWithinV

我正在尝试创建一个facebook组件(UIViewController的子类)来共享图片。现在可以在以下位置找到其状态的演示:

集成在ViewController中,我想这样使用它:

_shareSheet = [[FBSharePictureViewController alloc] initWithImage:self.currentImage.image andDelegate:self]; // Create the instance
[_shareSheet showWithinViewController:self]; // Actually display the sheet with animation
[_shareSheet hide]; // When needed, hide with animation
视图体系结构:

- [UIView] view
-- [UIView] overlay, a full-screen black view (when showWithinViewController: is called, slightly fade in to alpha 0.8)
-- [UIView] _sheetViewContainer, contains the sheet
---- [UIView] topView, contains the cancel and post buttons + a centered label
---- [UIView] bottomView, contains the picture we will share + an UITextView the user can enter text in.
-- spinner, an UIActivityIndicatorView
showWithinViewController功能:

- (void)showWithinViewController:(UIViewController *)parentViewController {

  [parentViewController addChildViewController:self]; // So the parent will foward actions like rotation,...

  // I want it to match the full size of my screen, so if we have a transparent
  // status bar the overlay will be visible under the status bar too
  CGRect frameBefore = self.view.frame;
  [parentViewController.view addSubview:self.view]; // view frame = {{0, 0}, {320, 460}}
  self.view.frame = frameBefore; // view frame = {{0, -20}, {320, 480}}

  self.view.hidden = NO;

  [UIView animateWithDuration:0.4 animations:^{
    // _sheetViewContainer.frame is originally centered horizontally and y is offscreen
    _sheetViewContainer.frame = [self getSheetViewFinalPos]; // I want the sheet to be centered between the UINavigationBar and the UIKeyboard
    self.overlay.alpha = 0.8f;
  } completion:^(BOOL finished) {
    self.cancelButton.enabled = YES;
    self.postButton.enabled = YES;
  }];
- (CGRect)getSheetViewFinalPos {
  CGFloat keyboardHeight = UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) ? 216 : 162;
  CGFloat navBarHeight = UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) ? 44 : 28;

  CGRect f = _sheetViewContainer.frame;
  f.origin.y = navBarHeight + 20 + (self.view.frame.size.height-20-navBarHeight-_sheetViewContainer.frame.size.height-keyboardHeight)/2;
  return f;
}
}

getSheetViewFinalPos函数:

- (void)showWithinViewController:(UIViewController *)parentViewController {

  [parentViewController addChildViewController:self]; // So the parent will foward actions like rotation,...

  // I want it to match the full size of my screen, so if we have a transparent
  // status bar the overlay will be visible under the status bar too
  CGRect frameBefore = self.view.frame;
  [parentViewController.view addSubview:self.view]; // view frame = {{0, 0}, {320, 460}}
  self.view.frame = frameBefore; // view frame = {{0, -20}, {320, 480}}

  self.view.hidden = NO;

  [UIView animateWithDuration:0.4 animations:^{
    // _sheetViewContainer.frame is originally centered horizontally and y is offscreen
    _sheetViewContainer.frame = [self getSheetViewFinalPos]; // I want the sheet to be centered between the UINavigationBar and the UIKeyboard
    self.overlay.alpha = 0.8f;
  } completion:^(BOOL finished) {
    self.cancelButton.enabled = YES;
    self.postButton.enabled = YES;
  }];
- (CGRect)getSheetViewFinalPos {
  CGFloat keyboardHeight = UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) ? 216 : 162;
  CGFloat navBarHeight = UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) ? 44 : 28;

  CGRect f = _sheetViewContainer.frame;
  f.origin.y = navBarHeight + 20 + (self.view.frame.size.height-20-navBarHeight-_sheetViewContainer.frame.size.height-keyboardHeight)/2;
  return f;
}
现在我的问题是:(如果访问上面的链接,您可以预览:)

我想为我的组件找到最好的方法,根据方向自动调整其框架的大小

  • 我尝试了
    UIAutoresizingMask
    ,但它的行为非常奇怪,我无法成功地使它工作:/
  • 我曾尝试使用
    viewWillLayoutSubviews
    方法,但如果我的视图被隐藏(当我旋转且视图未显示时),则此方法不起作用
  • 我曾尝试使用didRotateFromInterfaceOrientation,但当父视图控制器最初处于横向模式时,我显示我的组件,它将以纵向模式显示

如何实现这一点?

您是如何尝试设置
UIAutoresizingMask
?简而言之,将覆盖设置为flexibleWidth | flexibleHeight(因此始终全屏显示),_sheetViewContainer设置为allFlexible(边距+宽度,因此大小+位置将发生变化),将上/下视图设置为flexibleWidth | flexibleHeight。一切都是一团糟(转到上面的链接,第二个视频)。但我也使用layermask来实现圆角效果,你认为这可能是问题所在吗?