【发布时间】:2016-02-24 20:13:56
【问题描述】:
我的背景图片是用 UIView 扩展设置的。
extension UIView {
func addBackground() {
// screen width and height:
let width = UIScreen.mainScreen().bounds.size.width
let height = UIScreen.mainScreen().bounds.size.height
let imageViewBackground = UIImageView(frame: CGRectMake(0, 0, width, height))
imageViewBackground.image = UIImage(named: "index_clear")
// you can change the content mode:
imageViewBackground.contentMode = UIViewContentMode.ScaleAspectFill
self.addSubview(imageViewBackground)
self.sendSubviewToBack(imageViewBackground)
}}
对于 segue 动画,视图从左向右移动。背景图像比屏幕大得多,动画时可见。
如何剪切背景图像以完美地融入视图?
.ScaleAspectFit 完成了这项工作,但因为它是一张照片,所以看起来很糟糕。
非常感谢您的帮助。
【问题讨论】:
-
.ScaleAspectFill不会改变纵横比,因此不会扭曲图像,但会裁剪图像中不适合的部分 -
不,它没有。就像我说的那样,视图在带有 secondVC.frame = CGRectOffset(firstVC.frame, -screenWidth + screenWidth, 0.0) 的动画中移动,并且可以看到,背景图像大约是视图的 3 倍
-
你在图片视图上设置
clipsToBounds=true了吗? -
我现在做了,效果很好。谢谢您,请随时回答,以便我接受。谢谢!