0

我不确定如何实现像此屏幕截图顶部的滑动图像视图。

我正在使用 Eureka 表单,并且正在尝试将此滑动图像视图作为标题包含在内。

目前我正在使用自定义视图和这个

我认为我的问题的根源是手势识别器和“点击”方法引起的。Xcode 在行上抛出一个错误self.presentViewController(ctr,animated: true,completion:nil)。我知道它不能在 UIView 中显示视图控制器。我只是不确定如何实现在 UIView 子类中呈现视图控制器的相同结果。

这是我的代码:

class profilePicHeader: UIView {

let slideshow = ImageSlideshow()
var slideshowTransitioningDelegate: ZoomAnimatedTransitioningDelegate?

override init(frame: CGRect) {
    super.init(frame: frame)

    let localSource = [ImageSource(imageString: "GardenExample")!,ImageSource(imageString: "OvenExample")!]


    slideshow.backgroundColor = UIColor.whiteColor()
    slideshow.pageControlPosition = PageControlPosition.UnderScrollView
    slideshow.pageControl.currentPageIndicatorTintColor = UIColor.lightGrayColor();
    slideshow.pageControl.pageIndicatorTintColor = UIColor.blackColor();
    slideshow.contentScaleMode = UIViewContentMode.ScaleAspectFill


    slideshow.setImageInputs(localSource)


    let recognizer = UITapGestureRecognizer(target: self, action: #selector(profilePicHeader.click))
    slideshow.addGestureRecognizer(recognizer)

    slideshow.frame = CGRectMake(0, 0, 320, 200)
    slideshow.autoresizingMask = .FlexibleWidth
    self.frame = CGRectMake(0, 0, 320, 130)
    slideshow.contentMode = .ScaleAspectFit
    self.addSubview(slideshow)
}

func click() {
    let ctr = FullScreenSlideshowViewController()
    ctr.pageSelected = {(page: Int) in
        self.slideshow.setScrollViewPage(page, animated: false)
    }

    ctr.initialImageIndex = slideshow.scrollViewPage
    ctr.inputs = slideshow.images
    slideshowTransitioningDelegate = ZoomAnimatedTransitioningDelegate(slideshowView: slideshow, slideshowController: ctr)
    // Uncomment if you want disable the slide-to-dismiss feature on full screen preview
    // self.transitionDelegate?.slideToDismissEnabled = false
    ctr.transitioningDelegate = slideshowTransitioningDelegate
    self.presentViewController(ctr, animated: true, completion: nil)
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
      }
}
4

2 回答 2

0

我的解决方案是使用容器视图和页面视图控制器。您添加一个容器视图并设置自动布局约束来调整容器的大小,然后将所有图像添加到内部的页面视图控制器中。

于 2016-09-08T15:19:25.610 回答
0

如您所知,我们无法从 UIView 呈现 UIViewController。因此,要解决您的问题,您需要在窗口中添加 UIViewController 的视图并显示正确的动画。

为了执行这个任务,我们有一个很好的库调用 MJPopupViewController。通过使用它,您可以从 UIView 呈现具有不同过渡效果的 UIViewController。库:https ://github.com/martinjuhasz/MJPopupViewController

如果您在集成此库时遇到任何问题,请告诉我们。

谢谢。

于 2016-09-09T09:12:32.220 回答