OGeek|极客世界-中国程序员成长平台

标题: ios - UIPopoverController 中的 UIScrollView [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 16:28
标题: ios - UIPopoverController 中的 UIScrollView

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

这是弹出窗口中显示的 View Controller 中 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 时设置为指向图像。

这就是它的样子。

enter image description here

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



Best Answer-推荐答案


你需要做的是:

第一:

在显示为弹出框的 uiviewcontroller 中

override func viewWillAppear(animated: Bool) {
  super.viewWillAppear(animated)

      preferredContentSize = CGSize(width: collectionPreference.bounds.width, height: collectionPreference.bounds.height)
      println("I am appearing?")
}

然后从呈现弹出框的 View Controller 中:

使其符合 UIPresentationStyleForPresentingController 协议(protocol),

并实现这两件事:

第一:

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

祝你好运

关于ios - UIPopoverController 中的 UIScrollView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32933002/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4