2016-03-19 30 views
0

我有一个UIViewController与UIScrollView就可以了。我想在我的应用程序行为如下:为什么我不能在我的ios swift应用程序中设置我的UIScrollView的默认缩放?

1)用户打开应用程序,并认为,在正常尺寸的照片(在UIScrollView中的默认大小)

2)当照片的用户单水龙头,它会全屏显示,用户也可以放大并移动照片

3)当用户在全屏模式下再次点击照片时,它会从第1点开始缩小到原始尺寸)四处移动被禁用。

为了处理滚动和移动照片我决定去用这个插件:https://github.com/huynguyencong/ImageScrollView

我的代码如下:

@IBOutlet weak var requestPhoto: ImageScrollView! 

var originalPhotoSize :CGRect? 
var isPhotoOnFullScreen: Bool = false 

override func viewDidLoad() { 
    super.viewDidLoad() 

    let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "tapHandler:") 

    self.requestPhoto.addGestureRecognizer(tapGestureRecognizer) 
    self.requestPhoto.userInteractionEnabled = true 

    originalPhotoSize = requestPhoto.frame 
} 


override func viewDidAppear(animated: Bool) { 
    super.viewWillAppear(animated) 
    requestPhoto.scrollEnabled = false 
    requestPhoto.pinchGestureRecognizer?.enabled = false 
    requestPhoto.panGestureRecognizer.enabled = false 
    requestPhoto.zoomScale = 1 
} 

func tapHandler(sender: UITapGestureRecognizer) { 

    if sender.state == .Ended { 
     if(isPhotoOnFullScreen == true){ 
      self.requestPhoto.frame = originalPhotoSize! 
      self.requestPhoto.zoomScale = 1 
      self.requestPhoto.pinchGestureRecognizer?.enabled = false 
      self.requestPhoto.scrollEnabled = false 
      isPhotoOnFullScreen = false 
     }else{ 
      self.requestPhoto.frame = self.view.frame 
      self.requestPhoto.pinchGestureRecognizer?.enabled = true 
      self.requestPhoto.scrollEnabled = true 
      isPhotoOnFullScreen = true 
     } 

} 
} 

而且我确切的问题是:

1)当用户打开应用程序,他可以捏来放大对小照片(即使我设置了requestPhoto.pinchGestureRecognizer?.enabled = falseviewDidLoad

2)当用户点击照片时,它会全屏打开。这很好,但是当他捏缩放,并在某些点单击照片,它回到小尺寸,但缩放级别未设置为默认(即使我设置self.requestPhoto.zoomScale = 1

你可以帮助我解决上述两个问题?

====编辑

谈论问题没有。 1 - 当用户打开应用程序时,他可以捏合以放大照片,但是当他全屏打开图像并返回正常模式时 - 则缩放功能被禁用。为什么它从一开始就没有被禁用?

谈论问题没有。 2 - 不知怎的,这条线self.requestPhoto.zoomScale = 1不起作用,当我把它设置为1后立即打印self.requestPhoto.zoomScale的值,它仍然有一些不同的值,我不确定是否这个插件(https://github.com/huynguyencong/ImageScrollView)错误或我做错了什么?

回答

0

您可以使用本机UIScrollView来完成您的成就。您不需要使用第三方SDK。

如果您选择建立与本地ScrollViewDelegate您的应用程序,你可以使用上述设定的缩放水平这个scrollView委托方法。

func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? { 
     scrollView.minimumZoomScale = 1 
     scrollView.minimumZoomScale = 10 
     return self.imageView // Your Image View. 
    } 
+0

感谢您的支持!但是,至今为止,我决定留在第三方SDK并尝试修复我的错误,如果这不起作用,我会尝试使用您的解决方案!你也许知道我的问题可能是什么原因? – randomuser1

相关问题