5minho / DreamRecorder

mino & bran BoostCamp Project
6 stars 0 forks source link

AlarmListCell을 VoiceOver가 읽을 때 Time을 부자연스럽게(기수)로 읽음. #75

Closed YoonJuHo closed 7 years ago

YoonJuHo commented 7 years ago

목표: 공칠 삼십 오전 ~ 불라불라가 아닌 오전 일곱시 삼십분 ~ 불라불라로 읽어야함.

YoonJuHo commented 7 years ago

Date는 Date의 일종인 AlarmDate를 통해 descriptionForAlarmTime을 얻어 올 수 있다. DateFormatter를 통해서 Date로 부터 현지화된 String값을 가져올 수 있다.

여기서 문제는 dateFormatter의 timeStyle을 할당할 때 불필요한 요소까지 String에 포함된다는 것이다. 짧게 하기에는 적절하게 읽어 주지 않으므로 제한된다. 그렇다고 setLocalizedDateFormatFromTemplate를 통해서 "a hh:mm"를 할당해도 기수로 읽어버린다.

따라서 dateFormatter를 원하는 방향으로 읽어주면서 조금은 불필요한 내용을 포함하는 timeStyle의 .long을 통해서 얻어진 String값을 subString하기로 결정하였다.

*WeekdayButton과는 다르게 접근성을 UIView가 아닌 Controller에서 처리하도록 만듬.

YoonJuHo commented 7 years ago
/// 해당 시간(Self)을 시간, 분, AM/PM을 현지언어 텍스트로 변환한다.
        var descriptionForAlarmTime: String {

            let dateFormatter = DateFormatter()

            /// Date를 기수로 읽지 않기 위해서 tiemStyle을 long으로 설정한다.
            dateFormatter.timeStyle = .long
            dateFormatter.dateStyle = .none

            /// DateFormatter를 활용하여 Date로 부터 String값을 가져온다.
            let localizedString = dateFormatter.string(from: self.date)
            /// DateFormatter가 현지화한 String값은 GMT+X를 포함하고 있으므로 필요없는 문자열 값은 제거한다.
            if let gmtIndex = localizedString.characters.index(of: "G") {
                let lastIndex = localizedString.characters.index(gmtIndex, offsetBy: -4)
                return localizedString.substring(to: lastIndex)
            } else {
                return dateFormatter.string(from: self.date)
            }
        }
YoonJuHo commented 7 years ago

TODO: timeStyle을 .long으로 하였을 때 불필요한 정보("~~ xx초 +GMT")를 G라는 캐릭터로 Index값의 위치를 찾아서 그 값의 앞 -4까지 subString하여서 이상적인 description(ex. 오전 11시 30분)이라고 까지만 읽도록 하였다. 하지만 이는 G의 인덱스 위치값에 -4라는 하드코딩이 포함하고있다. timeFormat에서 ":"를 "시"와 "분"으로 읽어주는 방법이 이상적일 것인데 아직 모르겠다.