2016-07-07 18 views
0

私は、ユーザーが落とした地図ピンに最大3枚の画像を添付できるようにしています。現在、UIViewに表示される添付画像を表示するための小さなプレビューがあります。プレビューボタンを押すと、ユーザーにフルスクリーンイメージを表示させようとしています。下の画像プレビューボタンの例です。ここで一度画像をフルスクリーンで表示ボタンを押したとき

enter image description here

は、関連するコードです:

// Image preview 
    img1 = UIButton(frame:TCRectMake(x: 18,y:82,width:80,height:110)) 
    img1.backgroundColor = UIColor.clearColor() 
    img1.contentMode = .ScaleAspectFill 
    img1.clipsToBounds = true 
    img1.addTarget(self, action:"selectImage:", forControlEvents: UIControlEvents.TouchUpInside) 
    popupView.addSubview(img1) 

    img2 = UIButton(frame:TCRectMake(x: 100.8,y:82,width:80,height:110)) 
    img2.backgroundColor = UIColor.clearColor() 
    img2.contentMode = .ScaleAspectFill 
    img2.clipsToBounds = true 
    img2.addTarget(self, action:"selectImage:", forControlEvents: UIControlEvents.TouchUpInside) 
    popupView.addSubview(img2) 

    img3 = UIButton(frame:TCRectMake(x: 183,y:82,width:80,height:110)) 
    img3.backgroundColor = UIColor.clearColor() 
    img3.contentMode = .ScaleAspectFill 
    img3.clipsToBounds = true 
    img3.addTarget(self, action:"selectImage:", forControlEvents: UIControlEvents.TouchUpInside) 
    popupView.addSubview(img3) 

    ... 

// Save image to document 
func saveImageIntoDocument(resizeImage:UIImage,saveCompleted:((String)->())? = nil) 
{ 
    let documentsUrl = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first! 

    let timeStamp = "\((Int(Timestamp))).png" 
    let filePath = documentsUrl.relativePath!.stringByAppendingString("/\(timeStamp)") 
    if saveCompleted != nil 
    { 
     saveCompleted!(timeStamp) 
    } 
    UIImagePNGRepresentation(fixRotation(resizeImage))!.writeToFile(filePath, atomically: true) 

} 

これは、各プレビューボタンのコードです:

func image1Click(sender:UIButton) 
{ 
    print(sender.tag) 
} 
func image2Click(sender:UIButton) 
{ 
    print(sender.tag) 
} 
func image3Click(sender:UIButton) 
{ 
    print(sender.tag) 
} 

私は私は何かが逃したかどうかを知ってみましょう:)もし誰かがプレビューを見るのを助けることができたフルスクリーンは素晴らしいだろう!

答えて

0

これはあなたを助けるはずです。このコードはジェスチャを使用します。画像自体をクリックするとフルスクリーンになりますが、少なくともいくつかのヒントを取ることができます。

すべてをカバーする新しいイメージを作成することによって機能します。スーパービューからフルスクリーンイメージを隠すのはTapGestureRecognizerです。

@IBAction func imgTapped(sender: UITapGestureRecognizer) { 
    let imageView = sender.view as! UIImageView 
    let newImageView = UIImageView(image: imageView.image) 
    newImageView.frame = self.view.frame 
    newImageView.backgroundColor = .blackColor() 
    newImageView.contentMode = .ScaleAspectFit 
    newImageView.userInteractionEnabled = true 
    let tap = UITapGestureRecognizer(target: self, action: "dismissFullscreenImage:") 
    newImageView.addGestureRecognizer(tap) 
    self.view.addSubview(newImageView) 
} 

func dismissFullscreenImage(sender: UITapGestureRecognizer) { 
    sender.view?.removeFromSuperview() 
} 
+0

お返事のおかげで、何も私が実装したときに、これはたぶん私は間違って何か?それは行くべきをやっている:(起こるようですか? – Oscar

+0

画像がどこにあるかそれはのViewControllerに行く必要があります。 –

+0

はい、私はそれを置きますあなたが返信してくれてありがとうございました – Oscar

関連する問題