1

写真を共有するために Facebook コンポーネント (UIViewController のサブクラス) を作成しようとしています。その状態のデモンストレーションがここにあります: http://jeremy.gabriele.free.fr/SO/rotatesubvc/

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;
  }];

}

getSheetViewFinalPos 関数:

- (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 を使用しようとしましたが、親の ViewController が最初は横向きモードで、コンポーネントを表示すると縦向きモードで表示されます。

これを達成するにはどうしますか?

4

0 に答える 0