[toc]
iOS SwiftUI Version
이거 빗변 피타고라스로 구하면 117.8 xs 기준으로 반지름이 325 / 2 == 162.5 중심으로 부터 14멀어 162.5 - 14 - 117.8 == 30.7 인데 소수점 버려 그래서 빗변은 반지름 - 30 으로 비율 퉁
https://www.appcoda.com/learnswiftui/swiftui-texteditor.html
https://bigmountainstudio.wordpress.com/2020/07/26/394/
![image-20201119231211299](/Users/kyuhyeon/Library/Application Support/typora-user-images/image-20201119231211299.png)
var view = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
view.backgroundColor = .black
PlaygroundPage.current.liveView = view
let triangle = CAShapeLayer()
triangle.fillColor = UIColor.systemGreen.cgColor
triangle.path = createRoundedTriangle(width: 220, height: 200, radius: 15)
triangle.position = CGPoint(x: 140, y: 130)
view.layer.addSublayer(triangle)
func createRoundedTriangle(width: CGFloat, height: CGFloat, radius: CGFloat) -> CGPath {
let point1 = CGPoint(x: -width / 2, y: height / 2)
let point2 = CGPoint(x: 0, y: -height / 2)
let point3 = CGPoint(x: width / 2, y: height / 2)
let path = CGMutablePath()
path.move(to: CGPoint(x: 0, y: height / 2))
path.addArc(tangent1End: point1, tangent2End: point2, radius: radius)
path.addArc(tangent1End: point2, tangent2End: point3, radius: radius)
path.addArc(tangent1End: point3, tangent2End: point1, radius: radius)
path.closeSubpath()
return path
}
https://blckbirds.com/post/drawing-in-swiftui/
꼭 보자
Frame 은 View 본인의 height, width. 사이즈를 지정할 때. Padding 은 View 의 top, bottom, leading, trailing 를 지정할 때. Spacer 는 Stack 에 소속된 View들 사이의 일정한 거리를 지정할 때. GeometryReader 는 View의 부모뷰의 사이즈를 기준으로 본인의 사이즈를 조절할 때.
//ContentView는 edgesIgnoringSafeArea 무시합니다.
ContentView()
.background(Color.blue.edgesIgnoringSafeArea(.bottom))
RxSwift Observalbe -> AnyPulisher subscribe -> sink
onReceive -> RxCocoa .rx Publisher 넣어준 이벤트에 따라 action이 수행됨
변수에 넣는
@State
변수의 값을 관찰하다가 이를 사용하는 view를 업뎃
: view가 없어지기 전까지 메모리에 영원히 존재 할수 있음 외부에서 절대 사용 X
String, Int, Bool 단순 로컬 프로퍼티에 적합
$을 붙히면 쓰기 가능
@ObservableObject
@State와 같은 역활이나, 같은 View에 선언된 변수가 아닌 외부의 값에 의해 변화 될때 사용
※ ObjectBinding -> ObservableObject 변경됨.
EnvironmentObject
ObservableObject 를 준수하는 클래스는
@Published
속성으로 선언된 변수의 값이 변하려고 할때, willSet
외부에 퍼블리싱함.
class UserModel: ObservableObject {
@Published var userID: String = ""
}
struct SignInView: View {
@StateObject var user = UserModel()
var body: some View {
VStack {
// UserModel의 값이 변경될 때 전달 받을 수 있음
if !uesr.userID.isEmpty { Text("Hi, \(user.userID)) }
SignInButton()
.onTapGesture { user.userID = "Jaesung" }
}
}
}
class TimeCounter: ObservableObject {
@Published var count: Int = 0
func increase() {
count += 1
}
}
@ObservedObject
는 뷰 라이프 사이클에 의존
CountView의 body가 State 속성의 프로퍼티에 의해 업데이트가 된다면 TimeCounter = 0으로 초기화 됨
struct CountView: View {
@ObservedObject var counter = TimeCounter()
var body: some View {
VStack {
Text(counter.count)
Button(action: counter.increase) {
Text("Tap")
}
}
}
}
@StateObjects
는 독립개체
CountView의 body가 State 속성의 프로퍼티에 의해 업데이트가 되고 0으로 초기화 되지 않음
struct CountView: View {
@StateObject var counter = TimeCounter()
...
}
Observable 오브젝트를 Environment 오브젝트로 변환하면, 첫번째 뷰에서 두번째 뷰로 참조체를 전달할 필요없이 모든 뷰에서 Environment 오브젝트에 접근이 가능하다
https://eunjin3786.tistory.com/68
https://zeddios.tistory.com/1153
루트뷰 전환
https://www.python2.net/questions-750586.htm
curl -X GET "https://dapi.kakao.com/v2/local/search/keyword.json?page=1&size=15&sort=accuracy&query=%EB%B6%84%EC%8B%9D&category_group_code=FD6&x=126.9710952&y=37.554108&radius=500" \
-H "Authorization: KakaoAK {REST_API_KEY}"
https://dapi.kakao.com/v2/local/search/category.json?category_group_code=FD6&query=%EB%B6%84%EC%8B%9D&page=1&size=15&sort=accuracy&x=126.9710952&y=37.554108&radius=500
적용하기 https://www.raywenderlich.com/9335365-core-data-with-swiftui-tutorial-getting-started
내가 원하는건 SplashView -> MainView 전환 시 rootVC 인데 풀커버를 하게되면 아래처럼 덮어짐 모달임
Image("splash")
.edgesIgnoringSafeArea(.all)
.fullScreenCover(isPresented: .constant(true), content: {
MainView()
})
https://designcode.io/swiftui-handbook-lottie-animation
카카오맵 적용
https://aircook.tistory.com/entry/Kakao-Maps-API-with-Swift
카카오 지도
현재 위치
https://adrianhall.github.io/swift/2019/11/05/swiftui-location/
네트워크
https://www.swiftcompiled.com/mvvm-swiftui-and-combine/
컴바인
https://blog.gangnamunni.com/post/SwiftUI+CombineQuickLook/
컴바인 Zip
https://gist.github.com/zafarivaev/41241de9bb4b178950352f92733e4009 https://medium.com/better-programming/observe-the-completion-of-2-network-requests-using-combine-in-swift-5-6fc9e7304e4f
Advanced Combining Operator
https://sujinnaljin.medium.com/combine-advanced-combining-operator-1ee9928bc873
네트워크
https://github.com/freshOS/Networking
https://www.userdesk.io/blog/swift-networking-with-combine/
.font(.custom("AppleSDGothicNeo-Medium", size: 25))
Tine Light Regular Medium SemiBold Bold