问题
I have the following piece of code which works well for a legacy IOS app, but now no longer works in xcode 9:
The error I'm getting is:
'ContentMode' is not a member type of 'UIView'
Here is the code:
import Foundation
struct ImageViewLayout {
static func frameForImageWithSize(_ image: CGSize, previousFrame: CGRect, inContainerWithSize container: CGSize, usingContentMode contentMode: UIView.ContentMode) -> CGRect {
let size = sizeForImage(image, previousSize: previousFrame.size, container: container, contentMode: contentMode)
let position = positionForImage(size, previousPosition: previousFrame.origin, container: container, contentMode: contentMode)
return CGRect(origin: position, size: size)
}
回答1:
The enum type name UIView.ContentMode
is new in Swift 4.2, introduced in Xcode 10. Before that (e.g. Xcode 9, as you say) it was UIViewContentMode
.
来源:https://stackoverflow.com/questions/52416192/contentmode-is-not-a-member-type-of-uiview