我试图在UIImageView中以纵向和横向显示图像仅用于Ipad,当我将UIImageView添加到StoryBoard时,我将宽度和高度设置为768x365,图像显示完美,但如果Ipad旋转到横向,我想在1024x365中显示相同的图像。
我尝试以下但未成功。
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
let orientation = UIApplication.sharedApplication().statusBarOrientation
switch orientation {
case .Portrait, .PortraitUpsideDown:
// 4
imageView.frame = CGRect(x: 0.0, y: 0.0, width: 1024.0, height: 365)
self.imageView.setNeedsDisplay()
case .LandscapeLeft, .LandscapeRight:
imageView.frame = CGRect(x: 0.0, y: 0.0, width: 768.0, height: 365)
self.imageView.setNeedsDisplay()
}
PD:图像分辨率为1680x598