Skip to content

[2주 차 과제] 날씨 앱 구현#2

Open
yeonsu0-0 wants to merge 4 commits into
mainfrom
week2
Open

[2주 차 과제] 날씨 앱 구현#2
yeonsu0-0 wants to merge 4 commits into
mainfrom
week2

Conversation

@yeonsu0-0

@yeonsu0-0 yeonsu0-0 commented Oct 26, 2023

Copy link
Copy Markdown
Member

🌥️ Weather App

ezgif-3-63a085972a


💌To Reviewers

처음부터 끝까지 코드 베이스로 구현하는 건 처음이여서 이렇게 길게 오토레이아웃 관련 코드를 짜는 게 맞나,, 하는 의문이 있어요
일단 구현을 목표로 코드를 짰더니 코드가 엄청 길어졌어요🤯


image


위의 사진 속 데이터들을 만들 때 객체를 재활용 할 수 없다보니 하나씩 하나씩 객체를 만드느라 손목 부러지는 줄 알았는데
이런 동일한 틀에 내용만 바뀌는 더미 데이터를 구현할 때 더 나은 방법이 있을까요?

@yeonsu0-0 yeonsu0-0 self-assigned this Oct 26, 2023

@HELLOHIDI HELLOHIDI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

시험기간인데 고생많이했어요!!! 심화과제도 도전하고 Snapkit 이용해서 리팩토링 해도 좋을거 같습니당~

Comment on lines +156 to +219
self.navigationController?.isNavigationBarHidden = true

scrollView.showsVerticalScrollIndicator = false

self.view.addSubview(scrollView)
scrollView.addSubview(contentView)
scrollView.alwaysBounceVertical = true

self.contentView.backgroundColor = .black
self.contentView.addSubview(etcButton)
self.contentView.addSubview(appTitle)
self.contentView.addSubview(searchTextField)
self.contentView.addSubview(listView)

scrollView.translatesAutoresizingMaskIntoConstraints = false
contentView.translatesAutoresizingMaskIntoConstraints = false
etcButton.translatesAutoresizingMaskIntoConstraints = false
appTitle.translatesAutoresizingMaskIntoConstraints = false
searchTextField.translatesAutoresizingMaskIntoConstraints = false
listView.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([scrollView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor),
scrollView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
scrollView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
scrollView.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor)])

NSLayoutConstraint.activate([contentView.leadingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.leadingAnchor),
contentView.trailingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.trailingAnchor),
contentView.topAnchor.constraint(equalTo: scrollView.contentLayoutGuide.topAnchor, constant: 0),
contentView.bottomAnchor.constraint(equalTo: scrollView.contentLayoutGuide.bottomAnchor)])

contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor).isActive = true
let contentViewHeight = contentView.heightAnchor.constraint(greaterThanOrEqualTo: view.heightAnchor)
contentViewHeight.priority = .defaultLow
contentViewHeight.isActive = true

NSLayoutConstraint.activate([
etcButton.trailingAnchor.constraint(equalTo: self.contentView.trailingAnchor, constant: -10),
etcButton.topAnchor.constraint(equalTo: contentView.safeAreaLayoutGuide.topAnchor, constant: 8),
etcButton.heightAnchor.constraint(equalToConstant: 44),
etcButton.widthAnchor.constraint(equalToConstant: 44)
])

NSLayoutConstraint.activate([
appTitle.topAnchor.constraint(equalTo: etcButton.bottomAnchor, constant: 0),
appTitle.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 20)
])

NSLayoutConstraint.activate([
searchTextField.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 20),
searchTextField.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -20),
searchTextField.heightAnchor.constraint(equalToConstant: 40),
searchTextField.topAnchor.constraint(equalTo: appTitle.bottomAnchor, constant: 8)
])

NSLayoutConstraint.activate([
listView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 20),
listView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -20),
listView.heightAnchor.constraint(equalToConstant: 117),
listView.topAnchor.constraint(equalTo: searchTextField.bottomAnchor, constant: 15)
])

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapMyLocationView))
listView.addGestureRecognizer(tapGesture)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

viewDidLoad에 setStlye(), setLayout() 등 메소드로 구분해서 작성하면 훨씬 깔끔한 코드가 될거 같습니다!

return vc
}

func updateUIViewController(_ uiViewController: UIViewController, context: Context) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용하지 않는 메소드는 지워주면 좋을거 가탕요!

//

import UIKit
import SwiftUI

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용하지 않는 모듈은 삭제해주는게 좋을거 같아요!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용하지 않는 모듈은 삭제해주는게 좋을거 같아요!

아마 SwfitUI의 프리뷰 사용하려구 추가해둔 것 같아용 ?~?

@Naknakk Naknakk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이번 세미나때 배운 스냅킷과 덴으로 2차과제는 좀더 편하게 해봅시당 ㅎㅎㅎ
커스텀 뷰를 만들면 동일한 틀에 내용만 조금씩 바뀌는 화면을 보다 편하게 만들 수 있어요!
https://tong94.tistory.com/18
https://ios-development.tistory.com/399
https://hyerios.tistory.com/216
https://stackoverflow.com/questions/16442559/uibutton-with-custom-view-addtargetactionforcontrolevents-does-not-work

관련해서 유용했던 링크 첨부합니당 ㅎㅎ


class ListViewController: UIViewController {

let nextViewController = DetailViewController()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용되지 않은 것 같아서 삭제해도 좋을 것 같아요~

self.contentView.addSubview(appTitle)
self.contentView.addSubview(searchTextField)
self.contentView.addSubview(listView)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아요 노션 자료실에 있는 UIView extension
https://www.notion.so/dosopt/addSubView-73a4579df8ef485bb008a72521538e79?pvs=4
이용하면 subview 여러개 한번에 추가 할 수 있어용~~~ 강추!

혹은 forEach 구문으로 한번에 해줘도 좋을 것 같아요~

appTitle.translatesAutoresizingMaskIntoConstraints = false
searchTextField.translatesAutoresizingMaskIntoConstraints = false
listView.translatesAutoresizingMaskIntoConstraints = false

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 forEach쓰면 편해용~

//

import UIKit
import SwiftUI

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용하지 않는 모듈은 삭제해주는게 좋을거 같아요!

아마 SwfitUI의 프리뷰 사용하려구 추가해둔 것 같아용 ?~?

horizontalContentView.addSubview(verticalStackView8)
horizontalContentView.addSubview(verticalStackView9)
horizontalContentView.addSubview(verticalStackView10)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 스택뷰도 커스텀 뷰를 통해서 만들어 둔 뒤, 데이터만 넣어주는 식으로 생성하면 좋아요 !~!

@0seoYun 0seoYun left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

연두언니 과제하느라 넘넘 수고 많았어욤 !!!! ㅎㅎ 요번 과제도 아좌좌..

imageView.contentMode = .scaleAspectFill

view.addSubview(imageView)
view.sendSubviewToBack(imageView)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오..! 이런 메서드도 있군요!! sendSubviewToBack 내용 찾아보니 흥미롭네요 ㅎ,ㅎ

title.text = "나의 위치"
title.textColor = .white

view.addSubview(title)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

view.addSubview를 하나씩 해주시고 스타일 지정해주셨는데, 저는 아주 아주 갠취이지만 view.addSubviews로 한번에 add 해주는 게 깔끔해보이더라구요! extension으로 UIView+ 사용해보는 것두 왕추천드립니당 !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants