我有pageViewController
显示一组图片。当我从右向左滚动时,一切都很好,但是当我从左向右滚动时,所有图像都会移动(一块图像仍然可见:
我必须提一下,我在imageView
和superview
UIImageView
之间的故事板中应用约束来填充整个屏幕。
这是我的pageViewController:
ConversationContainerVC : UIPageViewControllerDataSource{
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
let itemController = viewController as! ConversationImageElementVC
if itemController.itemIndex > 0 {
return getItemController(itemController.itemIndex-1)
}
return nil
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let segueName = segue.identifier
if segueName == Segues.Main.ConversationEmbedSegue{
let destinationVC = segue.destinationViewController as! UIPageViewController
destinationVC.dataSource = self
pageViewController = destinationVC
}
}
private func setPageVCImages(){
if contentImages.count > 0{
let firstController = getItemController(0)!
let startingViewControllers = [firstController]
pageViewController.automaticallyAdjustsScrollViewInsets = false
self.pageViewController.setViewControllers(startingViewControllers as [AnyObject], direction: .Forward, animated: false, completion: nil)
}
}
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
let itemController = viewController as! ConversationImageElementVC
if itemController.itemIndex+1 < contentImages.count {
return getItemController(itemController.itemIndex+1)
}
return nil
}
private func getItemController(itemIndex: Int) -> ConversationImageElementVC? {
if itemIndex < contentImages.count {
let pageItemController = self.storyboard!.instantiateViewControllerWithIdentifier(Ids.Main.ConversationImageElementVC) as! ConversationImageElementVC
pageItemController.itemIndex = itemIndex
pageItemController.pollImageAssociated = contentImages[itemIndex]
return pageItemController
}
return nil
}
// MARK: - Page Indicator
func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
return 0
}
func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
return 0
}
}
这是我的pageViewControllerItem
源代码:
class ConversationImageElementVC: UIViewController {
var itemIndex = 0
var image: UIImage!
@IBOutlet weak var pollImage: UIImageView!
override func viewDidLoad() {
self.pollImage.image = image
}
}
答案 0 :(得分:0)
我最终通过将UIImageView clipsToBounds
属性设置为true并保持aspect fill
模式来解决此问题。
您还可以通过在UIImageView
身份检查器上启用“剪辑子视图”来设置故事板。