最小和最大缩放Xcode Swift

时间:2015-03-01 16:19:06

标签: ios xcode swift scrollview zoom

我的xcode项目有最大和最小缩放问题。我无法弄清楚如何添加这个。我在互联网上搜索试图解决这个问题,但我尝试过的代码都没有。请帮忙:)谢谢!

这是我到目前为止能够进行缩放的内容:

import UIKit

class DetailViewController: UIViewController, UIScrollViewDelegate {




@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var myDetailedImageView: UIImageView!


var myDetailedImageName: String?
var nameString: String?


override func viewDidLoad() {
    super.viewDidLoad()

    func minscale () {

    }


    scrollView.delegate = self

    self.myDetailedImageView.image = UIImage(named: myDetailedImageName!)

}


func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {



    return myDetailedImageView
}


// Do any additional setup after loading the view.


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


 /*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little     preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/

这是我的图像问题:

1 个答案:

答案 0 :(得分:4)

您需要像这样设置缩放。 self.scrollView.minimumZoomScale = 1.0 self.scrollView.maximumZoomScale = 10

import UIKit

class DetailViewController: UIViewController, UIScrollViewDelegate {




@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var myDetailedImageView: UIImageView!


var myDetailedImageName: String?
var nameString: String?


override func viewDidLoad() {
    super.viewDidLoad()

    scrollView.minimumZoomScale = 1.0
    scrollView.maximumZoomScale = 10
    scrollView.delegate = self

    self.myDetailedImageView.image = UIImage(named: myDetailedImageName!)

}


func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {



    return myDetailedImageView
}


// Do any additional setup after loading the view.


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


 /*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little     preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/

通常应该这样做。