티스토리 뷰
iOS(swift)
[Swift 4] Fakebook 만들기 - 5. NavigationBar, Tap Gesture, Dismiss Navigation Bar, Cell Animation
광그로 2017. 11. 25. 22:08#Add TapGesture #Dismiss NavigationBar #UIView Animation #ZoomIn #Cell Animation
프로젝트 코드 : https://github.com/LeeGwangYong/iOS_swift/tree/master/FaceBook
참고 사이트 : https://www.youtube.com/watch?v=NJxb7EKXF3U&list=PL0dzCUj1L5JHDWIO3x4wePhD8G4d1Fa6N
1. ViewController.swift 추가
ㄱ. CollectionView Cell 에 있는 ImageView를 그대로 ViewController에서 사용가능한 subView로 복제
1 2 3 4 5 6 7 8 | if let startingFrame = feedImageView.superview?.convert(feedImageView.frame, to: nil) { subView.image = feedImageView.image subView.contentMode = feedImageView.contentMode subView.clipsToBounds = true subView.frame = startingFrame view.addSubview(subView) } | cs |
ㄴ. 검정배경 추가
1234 blackView.backgroundColor = UIColor.blackblackView.frame = self.view.frameblackView.alpha = 0view.addSubview(blackView) cs
1 2 3 4 | blackView.backgroundColor = UIColor.black blackView.frame = self.view.frame blackView.alpha = 0 view.addSubview(blackView) | cs |
ㄷ. subView에 화면의 중앙으로 이동하는 Animation
123456789 UIView.animate(withDuration: 0.75, animations: {()->Void in let height = self.subView.frame.height let yPos = self.view.frame.height / 2 - height / 2 self.subView.frame = CGRect(x: 0, y: yPos, width: self.view.frame.width, height: height) self.navigationController?.navigationBar.alpha = 0 self.blackView.alpha = 1}) cs
1 2 3 4 5 6 7 8 9 | UIView.animate(withDuration: 0.75, animations: {()->Void in let height = self.subView.frame.height let yPos = self.view.frame.height / 2 - height / 2 self.subView.frame = CGRect(x: 0, y: yPos, width: self.view.frame.width, height: height) self.navigationController?.navigationBar.alpha = 0 self.blackView.alpha = 1 }) | cs |
ㄹ. NavigationBar 숨기기
1 | self.navigationController?.navigationBar.alpha = 0 | cs |
전체코드
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 | let blackView = UIView() let subView = UIImageView() var feedImageView: UIImageView? @objc func animateToCenter(feedImageView: UIImageView) { self.feedImageView = feedImageView if let startingFrame = feedImageView.superview?.convert(feedImageView.frame, to: nil) { feedImageView.alpha = 0 blackView.backgroundColor = UIColor.black blackView.frame = self.view.frame blackView.alpha = 0 view.addSubview(blackView) subView.image = feedImageView.image subView.contentMode = feedImageView.contentMode subView.clipsToBounds = true subView.frame = startingFrame view.addSubview(subView) UIView.animate(withDuration: 0.75, animations: {()->Void in let height = self.subView.frame.height let yPos = self.view.frame.height / 2 - height / 2 self.subView.frame = CGRect(x: 0, y: yPos, width: self.view.frame.width, height: height) self.navigationController?.navigationBar.alpha = 0 self.blackView.alpha = 1 }) } } | cs |
ㅁ. CollectionView DataSource 추가
1 2 3 4 5 6 7 8 9 10 | override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return postList.count } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FeedCollectionViewCell", for: indexPath) as! FeedCollectionViewCell cell.post = postList[indexPath.row] cell.feedController = self // [2. CustomCollectionViewCell.swift 수정] 과정 먼저 수행 return cell } | cs |
2. CustomCollectionViewCell.swift 수정
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | var feedController: FeedController? func setupCell(){ self.contentView.translatesAutoresizingMaskIntoConstraints = false widthConstraint.constant = UIScreen.main.bounds.size.width self.backgroundColor = UIColor.white statusTextView.font = UIFont.systemFont(ofSize: 14) statusTextView.isScrollEnabled = false feedImageView.contentMode = .scaleAspectFill feedImageView.layer.masksToBounds = true feedImageView.isUserInteractionEnabled = true feedImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(FeedCollectionViewCell.zoomIn))) } @objc func zoomIn() { feedController?.animateToCenter(feedImageView: feedImageView) } | cs |
'iOS(swift)' 카테고리의 다른 글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- MVVM
- 객체
- 백준
- 스택
- 생활코딩
- C++
- Grid
- 코딩야학
- Custom Cell
- Add TapGesture
- command
- listview
- DP
- 그래프
- 백준온라인
- 데이터 바인딩
- dfs
- BFS
- CollectionView
- 문자열
- FEED
- Fakebook
- Cell Animation
- CustomCollectionViewCell
- XAML
- 타일링
- BOJ
- WPF
- UIView Animation
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함