23.08.25 금

2023. 8. 31. 01:40·Study/🌱 SeSAC

tableview register 등등 클로저 구문에

imageview frame 지정 시점

💡 CustomTableViewCell 구현하기

✔️ UITableViewCell 생성

Untitled.png

→ 인터페이스 빌더 상에서 셀을 구현할 때 작동한다.

Untitled.png

✔️ view.addSubView / contentView.addSubView

Untitled.pngUntitled.png

view.addSubView

→ uiViewController의 변경할 수 없는 기본 view 위에 얹는 것

Untitled.png

tableViewCell은 Content View위에 다른 뷰들이 올라가는 것이다.

Untitled.png

⇒ 때문에 addSubView를 할 때 view가 아닌 contentView 위에 올려야 한다!

Untitled.png

contentView가 아닌 tableViewCell위에 올리는 것은 오류가 발생하지는 않지만 레이아웃 적용이 되지 않는다.

✔️ 커스텀 셀 등록

Untitled.png

CustomTableViewCell로 타입캐스팅

Untitled.png

테이블 뷰 관련 코드를 클로저 구문 안에 넣기

Untitled.png

🔎 인스턴스 생성 순서

Untitled.png

⇒ viewDidLoad()보다 클로저 구문이 먼저 실행된다.

CustomTableViewController 인스턴스 생성 직전에 클로저 구문이 우선 실행됨

Untitled.png

클로저 구문 내부에서 초기화를 실행하면 인스턴스가 아직 생성되지 않은 시점이기 때문에 초기화를 할 수 없다.

지연 초기화

lazy var로 viewdidload 시점 이후에 초기화를 하도록 한다.

Untitled.png

💡 UIImageView frame

스크린샷_2023-08-25_오전_10.55.50.png

이미지 뷰의 특성상 초기화 시 frame 크기를 지정해줘야 한다.

스크린샷_2023-08-25_오전_10.59.06.png

프레임 크기 지정해야 하지만 초기화 이후에 constraints를 지정하기 때문에 지정한 크기가 의미 없다.

스크린샷_2023-08-25_오전_10.59.32.png

.zero로 빈 값을 지정해줌

스크린샷_2023-08-25_오전_11.03.03.png

이미지 뷰 초기화 시 frame의 크기가 0이기 때문에 cornerRadius가 적용되지 않는다.

뷰 초기화 후에 제약조건 설정 시 크기를 설정해 주기 때문에 크기가 0인 상태로 적용이 된다.

때문에 cornerRadius 조건이 0으로 들어가게 된다.

크기를 100, 100으로 지정했다면?

스크린샷_2023-08-25_오전_11.07.07.png스크린샷_2023-08-25_오전_11.07.44.png

디자인 적용 시 크기가 100이기 때문에 corner radius가 50으로 계산 된 상태로 적용된다.

📍 해결 방법 - layoutSubViews()

Untitled.png스크린샷_2023-08-25_오전_11.11.06.png


💡 UIPageViewController

Intro

Onboarding

Walkthrough

가이드가 될 화면

뷰컨을 배열로 관리하여 페이지 뷰컨이 컨테이너 역할만 하는 것

가이드 화면 1이 등장 후 다음 가이드 화면 2가 나오는 형식

스크린샷_2023-08-25_오전_11.37.02.png

  1. 인트로 화면을 몇 개 사용할 것?
  2. 스크린샷_2023-08-25_오전_11.41.02.png
  3. 프로토콜 호출viewControllerBeforeviewControllerAfter
  4. 사용자가 스와이프 했을 때 현재 화면 다음 화면을 준비 또는 마지막 화면임을 알려줌
  5. 사용자가 스와이프 했을 때 이전 화면 또는 첫 화면임을 알려줌
  6. Untitled.png

📌 firstIndex

let example = [1, 2, 3, 1, 2, 6, 7, 8]   example.firstIndex(of: 2) // -> 1   example.firstIndex(of: 6) // -> 5   

✔️ viewControllerBefore

스크린샷_2023-08-25_오전_11.52.42.png

현재 보고있는 하나 더 전의 인덱스의 뷰컨을 리턴

첫번째 화면이면 nil을 리턴함

func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {         guard let currentIndex = list.firstIndex(of: viewController) else { return nil } //인덱스가 없으면 더이상 화면이 없는 것         let previousIndex = currentIndex - 1                  return previousIndex < 0 ? nil : list[previousIndex]              }      func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {                  guard let currentIndex = list.firstIndex(of: viewController) else { return nil }                  let nextIndex = currentIndex + 1                  return nextIndex >= list.count ? nil : list[nextIndex]     } 

✔️ 화면 순서 지정

Untitled.png

direction → .reverse 하면 순서 반대로!

Untitled.png

페이지 넘기는 것이 사용자 입장에서 불편할 수 있음

init으로 페이지 넘기는 스타일 설정이 가능하다

스크린샷_2023-08-25_오후_12.06.33.pngUntitled.png

페이지가 얼마나 남았는지 사용자에게 알려줘야 한다!

Untitled.png

UIPageViewController가 기본으로 가지고 있는 viewController가 있음

Untitled.png스크린샷_2023-08-25_오후_12.13.56.png

페이지 컨트롤 위치 커스텀은 안됨 → 별도로 구현해야 함

페이지 컨트롤 컬러 변경은 가능함

pageCurl style, vertical일 때는 사용이 불가능 함

class OnboardingViewController: UIPageViewController,                                     UIPageViewControllerDelegate, UIPageViewControllerDataSource {      //1.     var list: [UIViewController] = []          override init(transitionStyle style: UIPageViewController.TransitionStyle, navigationOrientation: UIPageViewController.NavigationOrientation, options: [UIPageViewController.OptionsKey : Any]? = nil) {         super.init(transitionStyle: .scroll, navigationOrientation: .horizontal)     }          required init?(coder: NSCoder) {         fatalError("init(coder:) has not been implemented")     }               override func viewDidLoad() {         super.viewDidLoad()                  list = [FirstViewController(), SecondViewController(), ThirdViewController()]         view.backgroundColor = .lightGray         delegate = self         dataSource = self                  guard let first = list.first else { return }         setViewControllers([first], direction: .forward, animated: true)              }          func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {         guard let currentIndex = list.firstIndex(of: viewController) else { return nil } //인덱스가 없으면 더이상 화면이 없는 것         let previousIndex = currentIndex - 1                  return previousIndex < 0 ? nil : list[previousIndex]              }      func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {                  guard let currentIndex = list.firstIndex(of: viewController) else { return nil }                  let nextIndex = currentIndex + 1                  return nextIndex >= list.count ? nil : list[nextIndex]     }          func presentationCount(for pageViewController: UIPageViewController) -> Int {         return list.count     }          // 보고있는 페이지에 따라 페이지 컨트롤이 변경되어야 한다.     func presentationIndex(for pageViewController: UIPageViewController) -> Int {         guard let first = viewControllers?.first, let index = list.firstIndex(of: first) else { return 0 }         return index     }      } 

container view

스크린샷_2023-08-25_오후_12.26.35.png

viewController 안에 viewController 넣기

viewController 내에 page viewController 넣어 사용하기 → 컬렉션 뷰처럼 사용

스크린샷_2023-08-25_오후_12.28.02.png

코드 구현 매우 복잡함 → 값 전달 구현이 힘들다

'Study > 🌱 SeSAC' 카테고리의 다른 글

23.08.29 화  (0) 2023.08.31
23.08.28 월  (0) 2023.08.31
23.08.24 목  (0) 2023.08.31
23.08.23 수  (2) 2023.08.31
23.08.22 화  (0) 2023.08.31
'Study/🌱 SeSAC' 카테고리의 다른 글
  • 23.08.29 화
  • 23.08.28 월
  • 23.08.24 목
  • 23.08.23 수
김졀니
김졀니
🍎 iOS 개발
  • 김졀니
    졀니의 개발 공부✨
    김졀니
  • 전체
    오늘
    어제
    • 분류 전체보기
      • iOS
        • Swift
        • UIKit&SwiftUI
        • RxSwift&Combine
        • WWDC
      • Study
        • 🚨 TroubleShooting
        • 🌱 SeSAC
  • 블로그 메뉴

    • 홈
    • Github
  • 인기 글

  • 최근 글

  • 태그

    displayPriority
    Swift
    ios
    actor
    swift concurrency
    pointfree
    layoutIfNeeded
    Realm
    RxSwift
    wwdc23
    traits
    CLLocation
    이미지 캐싱
    인앱리뷰
    observable
    kingfisher header
    swiftdata
    mapkit
    위치 권한
    FileManager
    clipstobounds
    Sendable
    @PropertyWrapper
    의존성 주입
    Drawing Cycle
    mainactor
    동시성프로그래밍
    concurrency
    ReactorKit
    OperationQueue
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.3
김졀니
23.08.25 금
상단으로

티스토리툴바