【问题标题】:UIScrollView in UIPopoverControllerUIPopoverController 中的 UIScrollView
【发布时间】:2015-10-04 11:35:25
【问题描述】:

我正在努力启用使用UIScrollView 放大UIPopoverController。 scrollView 是 600x600,它应该显示一个显示UIImageView 的视图控制器。图像显示,但未居中。

这是弹出窗口中显示的视图控制器中viewDidLoad 方法的代码。

- (void)viewDidLoad {
    self.imageView = [[UIImageView alloc] init];
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    self.imageView.image = self.image;

    self.scrollView = [[UIScrollView alloc] init];
    self.scrollView.backgroundColor = [UIColor greenColor];
    [self.scrollView setContentSize:self.imageView.image.size];
    [self.scrollView setDelegate:self];

    [self.imageView setFrame:CGRectMake(0, 0, 600, 600)];
    self.view = self.scrollView;
    [self.scrollView addSubview:self.imageView];
    // Do any additional setup after loading the view.
}

UIScrollViewUIImageView 在弹出窗口中显示的 UIViewController 内声明为属性。 image 是另一个属性,在创建 UIViewController 时设置为指向图像。

这就是它的样子。

我想将图像置于弹出框的中心并使其适合。我怎样才能做到这一点?谢谢。

【问题讨论】:

    标签: ios uiscrollview uiimageview


    【解决方案1】:

    你需要做的是:

    第一:

    在显示为弹出框的 uiviewcontroller 中

    override func viewWillAppear(animated: Bool) {
      super.viewWillAppear(animated)
    
          preferredContentSize = CGSize(width: collectionPreference.bounds.width, height: collectionPreference.bounds.height)
          println("I am appearing?")
    }
    

    然后从呈现弹出框的视图控制器中:

    使其符合 UIPresentationStyleForPresentingController 协议,

    并实现这两件事:

    第一:

    func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
      return UIModalPresentationStyle.None
    }
    

    第二个:在你的 prepareforsegue 方法中:

    if let identifier = segue.identifier {
        if identifier == "segueToYourPopoverVC" {
            if let pVC = segue.destinationViewController as? YourPopoverVC {
    
                let ppc = pVC.popoverPresentationController
                ppc?.delegate = self
            }
         }
    }
    

    祝你好运

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-25
      • 2011-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多