iOS(swift)

[Swift 4] Fakebook 만들기 - 6. Add TapGesture, UIView Animation, ZoomOut, Cell Animation

광그로 2017. 11. 25. 23:24
#Add TapGesture #UIView Animation #ZoomOut #Cell Animation
프로젝트 코드 : https://github.com/LeeGwangYong/iOS_swift/tree/master/FaceBook
참고 사이트 : https://www.youtube.com/watch?v=NJxb7EKXF3U&list=PL0dzCUj1L5JHDWIO3x4wePhD8G4d1Fa6N



1. ViewController.swift 추가
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
@objc func animateToCenter(feedImageView: UIImageView)
    {
        self.feedImageView = feedImageView
        
        if let startingFrame = feedImageView.superview?.convert(feedImageView.frame, to: nil)
        {
             ...
   
            subView.image = feedImageView.image
            subView.contentMode = feedImageView.contentMode
            subView.clipsToBounds = true
            subView.frame = startingFrame
            subView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(FeedController.zoomOut)))
            subView.isUserInteractionEnabled = true
            view.addSubview(subView)
            
            ...
        }
    }
    
    @objc func zoomOut()
    {
        
        if let startingFrame = feedImageView!.superview?.convert(feedImageView!.frame, to: nil)
        {
            UIView.animate(withDuration: 0.75, animations:{()->Void in
                self.subView.frame = startingFrame
                self.blackView.alpha = 0
                self.navigationController?.navigationBar.alpha = 1
            }, completion: { (didComplete) in
                self.subView.removeFromSuperview()
                self.blackView.removeFromSuperview()
                self.feedImageView?.alpha = 1
            })
        }
    }
cs