[SwiftUI] Popover

RudinP·2025년 6월 30일
0

Study

목록 보기
305/325

  • 팝오버는 항상 어떤 뷰나 좌표에서 표시된다. 이는 Anchor라고 불린다.
  • 여기서는 +버튼
  • 아이폰에서는 Card Modal로 대신 표시된다.
struct Popover: View {
	@State private var showPopover = false

	var body: some View {
    	Button(action: {
        	showPopover = true
        }, label: {
        })
        .popover(isPresented: $showPopover, attachmentAnchor: .rect(Anchor<CGRect>.Source.bounds)) {
        	//표시할 뷰 리턴
            FormView()
        }
    }
}
  • State var 필수
  • attachmentAnchor에는 frame 혹은 source가 올 수 있다.
    • 이 코드에서는 버튼의 범위
  • 크기를 직접 입력하지 않거나 파악이 어렵다면 가장 작은 크기로 표시된다.
    • 원하는 크기를 지정해주는 것이 좋다.
struct Popover: View {
	...
    	//anchor도 기본값 사용 가능
        .popover(isPresented: $showPopover) {
        	//표시할 뷰 리턴
            FormView()
            	.frame(minWidth: 320, minHeight: 400)
        }
    }
}
profile
iOS 개발자가 되기 위한 스터디룸...

0개의 댓글