Instagram의 복제본을 만들려고합니다. 3 개의 다른 셀을 반환하는 UICollectionViewController를 사용하기로 결정하고 가로 방향으로 스크롤 방향을 설정하고 페이지 매김을 true로 설정하고, 그래서 내가 2 개의 수직 셀에 3 개의 서로 다른 페이지를 가질 수있다. 2 개의 다른 uicollectionviewcell은 중첩되어있다. 1은 dm을 위해, 1은 사용자가 도착했을 때 탐색 바를 숨길 때 문제가된다. 인스 타 그램에는 피드 셀과 메시징 셀에 대해 탐색 줄이 표시되지만 카메라 셀에는 표시되지 않기 때문에 카메라로 전송할 수 있습니다. 아래는 maincollectionviewcontroller에 대한 나의 코드이다. 나는 비슷한 문제를 해결하기 위해 무슨 짓을다른 셀 크기를 사용하여 UICollectionviewcell을 세로로 렌더링하는 방법
import UIKit
import AVFoundation
class MainViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
let cellID = "cellId"
let messageCellID = "messageCellID"
let cameraCellID = "cameraCellID"
var swipeRight = UISwipeGestureRecognizer()
override func viewDidLoad() {
super.viewDidLoad()
let titleImage = UIImageView(image: #imageLiteral(resourceName: "Instagram_logo"))
titleImage.layer.masksToBounds = true
self.navigationItem.titleView = titleImage
setupCollectionView()
setupSwipeGesture()
}
// //Swipe right to get camera
// func setupSwipeGesture() {
// swipeRight.direction = .right
// self.navigationController?.isNavigationBarHidden = true
// let cameraViewController = ViewController()
// cameraViewController.transitioningDelegate = self
// navigationController?.pushViewController(cameraViewController, animated: true)
// }
func setupSwipeGesture() {
print("trying to swipe")
swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(swiped))
self.view.addGestureRecognizer(swipeRight)
swipeRight.direction = .right
}
func swiped(){
print("swipping to get Camera")
self.navigationController?.isNavigationBarHidden = true
let cameraViewController = ViewController()
cameraViewController.transitioningDelegate = self
navigationController?.pushViewController(cameraViewController, animated: true)
}
func setupCollectionView(){
collectionView?.backgroundColor = .white
collectionView?.register(MainViewFeedCellCollectionViewCell.self, forCellWithReuseIdentifier: cellID)
collectionView?.register(MainViewMessagedFeedCell.self, forCellWithReuseIdentifier: messageCellID)
collectionView?.register(MainViewCameraFeed.self, forCellWithReuseIdentifier: cameraCellID)
collectionView?.isPagingEnabled = true
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
scrollToMenuIndex(menuIndex: 0)
}
func goBackToMainPage(){
scrollToMenuIndex(menuIndex: 0)
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if (indexPath.item == 2){
return collectionView.dequeueReusableCell(withReuseIdentifier: messageCellID, for: indexPath)
}
else if (indexPath.item == 0){
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cameraCellID, for: indexPath)
return cell
}
else if (indexPath.item == 1){
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellID, for: indexPath)
return cell
}
else{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellID, for: indexPath)
return cell
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
print("\(indexPath.row)")
// if indexPath.row == 0{
// navigationController?.isNavigationBarHidden = true
// return CGSize(width: view.frame.width, height:` view.frame.height)
//}
return CGSize(width: view.frame.width, height: view.frame.height - 70)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
func scrollToMenuIndex(menuIndex: Int){
let index = IndexPath(item: menuIndex, section: 0)
collectionView?.scrollToItem(at: index, at: .centeredHorizontally, animated: true)
}
}