gpt4 book ai didi

ios - 使用 Aspect Fill 图像模式的奇怪的 UIPageViewController 滑动行为

转载 作者:搜寻专家 更新时间:2023-10-31 21:53:17 25 4
gpt4 key购买 nike

我刚刚创建了一个包含页面内容 View Controller 的 UIPageViewController,它由单个 ImageView 和一个 Button 组成。它几乎完美无缺地工作,但是当我尝试仅在垂直 View 中滑动 View 时,它有一个主要问题,为我的 ImageView 设置了 Aspect Fill 模式(这基本上是为此设置的)。

您可以在此处看到此行为:https://youtu.be/2yl6UXbUGQg

我正在使用自动布局,Button 约束与 ImageView(全尺寸)对齐,ImageView 约束设置为 Superview...

代码:

1) UIPageViewController:

class ViewController: UIPageViewController, UIPageViewControllerDataSource {

var arrPageTitle: NSArray = NSArray()
var arrPagePhoto: NSArray = NSArray()

override func viewDidLoad() {
super.viewDidLoad()

arrPageTitle = ["page 1", "page 2", "page 3"]
arrPagePhoto = ["slider-1.jpg", "slider-2.jpg", "slider-3.jpeg"]

self.dataSource = self
self.setViewControllers([getViewControllerAtIndex(0)] as [UIViewController],
direction: .Forward,
animated: false,
completion: nil)
}

func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
let pageContent: PageContentViewController = viewController as! PageContentViewController
var index = pageContent.pageIndex
if ((index==0) || (index == NSNotFound)) {
return nil
}
index -= 1
return getViewControllerAtIndex(index)
}

func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
let pageContent: PageContentViewController = viewController as! PageContentViewController
var index = pageContent.pageIndex
if index == NSNotFound {
return nil
}
index += 1
if index == arrPageTitle.count {
return nil
}
return getViewControllerAtIndex(index)
}

func getViewControllerAtIndex(index: NSInteger) -> PageContentViewController {
let pageContentViewController = self.storyboard?.instantiateViewControllerWithIdentifier("PageContentViewController") as! PageContentViewController
pageContentViewController.strTitle = "\(arrPageTitle[index])"
pageContentViewController.strPhotoName = "\(arrPagePhoto[index])"
pageContentViewController.pageIndex = index
return pageContentViewController
}
}

2) 内容 View Controller ,UIViewController:

class PageContentViewController: UIViewController {

@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var labelTitle: UIButton!

var pageIndex: Int = 0
var strTitle: String!
var strPhotoName: String!


override func viewDidLoad() {
super.viewDidLoad()

self.imageView.image = UIImage(named: self.strPhotoName)
self.labelTitle.setTitle(self.strTitle, forState: .Normal)
}
}

最佳答案

来自一个 View Controller 的 ImageView 正在溢出到其他 View Controller ,因为您需要在 ImageView 上将 clipsToBounds 设置为 true。这将防止 ImageView 的内容超出 ImageView 的范围。

关于ios - 使用 Aspect Fill 图像模式的奇怪的 UIPageViewController 滑动行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37014027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com