Share
Embed
iOSのウィジェットでも猫走らせたい / iOSDC Japan 2022 Day2 Unconference
iOSDC Japan 2022 Day2 14:00~ Unconference トーク
Kyome (Takuto Nakamura)
September 12, 2022
Transcript
62 slides
-
iOSDC Japan 2022 - Unconference #iosdc #unconference ࣗݾհ IUUQTLZPNFJP ,ZPNF
,ZPNFTVLF macOS͚ͷϢʔςΟϦςΟΞϓϦ։ൃऀʢझຯ݉෭ۀʣ ϝχϡʔόʔৗறܕΞϓϦɺApp Extension ͕ಘҙ ීஈαΠϘζͰ kintoneϞόΠϧ ։ൃ͍ͯ͠·͢ʂ -
iOSDC Japan 2022 - Unconference #iosdc #unconference What’s RunCat? RunCat
macOS ͚ͷϝχϡʔόʔৗறܕΞϓϦ ೣͷΔεϐʔυͰ CPU ෛՙ͕Θ͔Δ ΞΫςΟϏςΟɾΠϯδέʔλʔ -
iOSDC Japan 2022 - Unconference #iosdc #unconference What’s RunCat? macOS൛ͷRunCat
CAKeyframeAnimation Λͬͯύϥύϥອը ͷཁྖͰΞχϝʔγϣϯ͍ͯ͠Δʢແݶϧʔϓʣ ఆظతʹCPUෛՙΛऔಘͯ͠ɺͦͷʹج͍ͮͯΞχϝʔγϣϯͷ speed Λߋ৽͍ͯ͠Δ cat-0 cat-1 cat-2 cat-3 cat-4 Speed -
iOSDC Japan 2022 - Unconference #iosdc #unconference What’s RunCat? speed
Λߋ৽͢ΔࡍʹΞχϝʔγϣϯ͕Ϧηοτ͞ΕΔͷͰɺ ରࡦ͠ͳ͍ͱΞχϝʔγϣϯ͕ΨΫΨΫͯ͠͠·͏ ☝︎ ͜Μͳײ͡ -
iOSDC Japan 2022 - Unconference #iosdc #unconference What’s RunCat? speed
Λߋ৽͢ΔࡍʹΞχϝʔγϣϯ͕Ϧηοτ͞ΕΔͷͰɺ ରࡦ͠ͳ͍ͱΞχϝʔγϣϯ͕ΨΫΨΫͯ͠͠·͏ cat-0 cat-1 cat-2 cat-3 cat-4 Speed มߋ -
iOSDC Japan 2022 - Unconference #iosdc #unconference What’s RunCat? speed
Λߋ৽͢ΔࡍʹΞχϝʔγϣϯ͕Ϧηοτ͞ΕΔͷͰɺ ରࡦ͠ͳ͍ͱΞχϝʔγϣϯ͕ΨΫΨΫͯ͠͠·͏ cat-0 cat-1 cat-2 cat-3 cat-4 Speed มߋ ☝︎ ࣍ͷΞχϝʔγϣϯ cat-3 ͔Β ࢝Ίͳ͍ͱεϜʔζʹͳΒͳ͍ -
iOSDC Japan 2022 - Unconference #iosdc #unconference What’s RunCat? speed
Λߋ৽͢ΔࡍʹΞχϝʔγϣϯ͕Ϧηοτ͞ΕΔͷͰɺ ରࡦ͠ͳ͍ͱΞχϝʔγϣϯ͕ΨΫΨΫͯ͠͠·͏ γʔϜϨεʹΓସ͑ΔͨΊɺߋ৽લʹ CALayer ͷ timeO ff set ͱ beginTime Λ੍ޚ్ͯ͠த͔ΒΞχϝʔγϣϯ͕࢝·ΔΑ͏ʹ͢Δ ☝︎ cat-3 ͔Β࢝·Γ cat-2 ͰऴΘΔΞχϝʹ͢Δ cat-3 cat-4 cat-0 cat-1 cat-2 -
iOSDC Japan 2022 - Unconference #iosdc #unconference What’s RunCat? ͜ͷΑ͏ͳεϐʔυ్͕தͰมԽ͢ΔແݶϧʔϓͷίϚૹΓ
ΞχϝʔγϣϯΛ࣮ݱͰ͖Δ࠷దखஈ͕ CAKeyframeAnimation Core Animation ͍͢͝ʂ -
iOSDC Japan 2022 - Unconference #iosdc #unconference WidgetKit ग़ͨ͠ͳΜ͔Ͱ͖ͦ͏ 2020ͷKyomeࢯ
※ 2020 iOS 14 ͕ൃද͞Ε WidgetKit ͕ಋೖ͞Ε·ͨ͠ɻ -
iOSDC Japan 2022 - Unconference #iosdc #unconference ઈରʹΞχϝʔγϣϯͤͨ͘͞ͳ͍ 74
Կͱͯ͠ΟδΣοτͰೣΒ͍ͤͨɾ -
iOSDC Japan 2022 - Unconference #iosdc #unconference Try 1: ͱΓ͋͑ͣૉʹΞχϝʔγϣϯࢼͯ͠ΈΔ
in App struct RotateItemView: View { @State var flag: Bool = false var body: some View { Image(systemName: "paperplane") .resizable() .frame(width: 100, height: 100, alignment: .center) .rotationEffect(Angle(degrees: flag ? 0 : 360)) .animation( Animation.linear(duration: 2) .repeatForever(autoreverses: false), value: flag ) .onAppear { flag.toggle() } } } -
iOSDC Japan 2022 - Unconference #iosdc #unconference Try 1: ͱΓ͋͑ͣૉʹΞχϝʔγϣϯࢼͯ͠ΈΔ
in Widget struct RotateItemView: View { @State var flag: Bool = false var body: some View { Image(systemName: "paperplane") .resizable() .frame(width: 100, height: 100, alignment: .center) .rotationEffect(Angle(degrees: flag ? 0 : 360)) .animation( Animation.linear(duration: 2) .repeatForever(autoreverses: false), value: flag ) .onAppear { flag.toggle() } } } Ξχϝʔγϣϯ͠ͳ͍ 💦 -
iOSDC Japan 2022 - Unconference #iosdc #unconference struct CatTimerView: View
{ @State var catIndex: Int = 0 let timer = Timer .publish(every: 0.1, on: .main, in: .default) .autoconnect() var body: some View { Image("cat-\(catIndex)") .onReceive(timer) { _ in catIndex = (catIndex + 1) % 5 } .padding() } } Try 2: TimerΛͬͯίϚૹΓͯ͠ΈΔ in App -
iOSDC Japan 2022 - Unconference #iosdc #unconference struct CatTimerView: View
{ @State var catIndex: Int = 0 let timer = Timer .publish(every: 0.1, on: .main, in: .default) .autoconnect() var body: some View { Image("cat-\(catIndex)") .onReceive(timer) { _ in catIndex = (catIndex + 1) % 5 } .padding() } } Try 2: TimerΛͬͯίϚૹΓͯ͠ΈΔ in Widget Γಈ͔ͳ͍ 💧 -
iOSDC Japan 2022 - Unconference #iosdc #unconference var animatedCatImage: Image?
{ if let uiImage = UIImage.animatedImageNamed("cat-", duration: 1) { return Image(uiImage: uiImage) } return nil } Try 3: ͦ͏ͩ UIKit ʹཔΖ͏ʂ in App UIImage.animatedImageNamed(_:duration:) Λ͑ɺ ࿈൪ʹͳ͍ͬͯΔϑΝΠϧ໊ͷը૾ΛΞχϝʔγϣϯԽ ͞ΕͨҰͭͷ UIImageʹͰ͖Δ͕… UIImageView ͩͱಈ͚͘Ͳ SwiftUIͷImageʹೖΕΔͱಈ͔ͳ͍ -
iOSDC Japan 2022 - Unconference #iosdc #unconference struct CatRepView: UIViewRepresentable
{ typealias UIViewType = UIImageView let uiImage: UIImage? init() { uiImage = UIImage.animatedImageNamed("cat-", duration: 1) } func makeUIView(context: Context) -> UIImageView { let imageView = UIImageView(image: uiImage) imageView.contentMode = .scaleAspectFit return imageView } func updateUIView(_ uiView: UIImageView, context: Context) {} } Try 4: UIViewRepresentable ͰͲ͏ͩʂ ࣌ͷදࣔΛ࠶ݱͨ͠ͷ ❗ ͔ͯɺφχίϨ!! UIKit ༝དྷͷ View ΟδΣοτͷதͰແޮ -
iOSDC Japan 2022 - Unconference #iosdc #unconference var catGIFImage: Image?
{ if let asset = NSDataAsset(name: "runcat-gif"), let uiImage = UIImage(data: asset.data) { return Image(uiImage: uiImage) } return nil } Try 5: GIFΛಡΈࠐΜͰΈΔ in App ͦͦΟδΣοτ͡Όͳͯ͘ಈ͔ͳ͍ -
iOSDC Japan 2022 - Unconference #iosdc #unconference WWDC 2022 ʹͯ
Live Activities ൃද -
iOSDC Japan 2022 - Unconference #iosdc #unconference Live Activities ref:
AppleɺiOS 16Ͱಋೖ͞ΕΔڞ༗ͱίϛϡχέʔγϣϯͷͨΊͷ৽͍͠ํ๏Λൃද - Apple (ຊ) https://www.apple.com/jp/newsroom/2022/06/apple-unveils-new-ways-to-share-and-communicate-in-ios-16/ -
iOSDC Japan 2022 - Unconference #iosdc #unconference Live Activities ref:
Keynote (ASL) - WWDC22 - Videos - Apple Developer. https://developer.apple.com/videos/play/wwdc2022/111/ -
iOSDC Japan 2022 - Unconference #iosdc #unconference Live Activities ref:
Keynote (ASL) - WWDC22 - Videos - Apple Developer. https://developer.apple.com/videos/play/wwdc2022/111/ -
iOSDC Japan 2022 - Unconference #iosdc #unconference Try 6: Live
Activities ΛͬͯΈΔ Live Activities ActivityKit Framework Λ࣮ͬͯ͢Δ ActivityKit Xcode 14 beta 4~6 Ͱ͑Δ Xcode 14 RC ʹೖ͍ͬͯͳ͍ ૣࢼ͍ͯ͠ΔਓͷهࣄGitHubͷιʔε*͕͋ΔͷͰ࣮ ͦΜͳʹ͘͠ͳ͍ * Create Live Activities With ActivityKit on iOS 16 | by Batikan Sosun | Aug, 2022 | Better Programming https://betterprogramming.pub/create-live-activities-with-activitykit-on-ios-16-beta-4766a347035b -
iOSDC Japan 2022 - Unconference #iosdc #unconference Try 6: Live
Activities ΛͬͯΈΔ ࢼͯ͠Θ͔ͬͨ͜ͱ Live Activities جຊతʹΟδΣοτͱҰॹ ϩοΫεΫϦʔϯʹදࣔͰ͖ΔΟδΣοτͱ͍͏ײ͡ ΓΞχϝʔγϣϯͰ͖ͳ͍😫 ं͕ಈ͍͍ͯΔΑ͏ʹݟ͑ͨͷɺSliderͷϊϒͷը૾Λม͍͚͑ͯͨͩ ߋ৽࣌ʹϊϒͷҠಈΞχϝʔγϣϯ͕࣮ߦ͞ΕΔ λΠϚʔ Text(date: Date, style: Text.DateStyle) Λ࣮͑Ͱ͖Δ ͔͠ɺiOS 14͔Β͜Ε͋ͬͨʢΒͳ͔ͬͨ..ʣ -
iOSDC Japan 2022 - Unconference #iosdc #unconference Calligraphr ͱ͍͏ϑΥϯτΛࣗ࡞Ͱ͖Δ αʔϏεΛͬͯೣϑΥϯτΛ࡞
Δೣ̑ϑϨʔϜͳͷͰɺ 0~4ͱ5~9ͷ̎पࢦఆ͢Δ ग़དྷ্͕ͬͨOpenTypeϑΥϯτΛ ϓϩδΣΫτʹऔΓࠐΉ Try 7: λΠϚʔ͕ಈ͔ͤΔͳΒೣϑΥϯτͰࠩ͠ସ͑Ε͍͍͡Όͳ͍ ref: Calligraphr. https://www.calligraphr.com/en/webapp/app_home/?/ -
iOSDC Japan 2022 - Unconference #iosdc #unconference struct ContentView: View
{ var body: some View { Text(Date(), style: .timer) .font(.custom("Runningcat-Regular", size: 150)) } } in App ͱΓ͋͑ͣී௨ͷSwiftUI AppͳΒػೳͨ͠ʂ ͳΜ͔ΧϫΠΠ Try 7: λΠϚʔ͕ಈ͔ͤΔͳΒೣϑΥϯτͰࠩ͠ସ͑Ε͍͍͡Όͳ͍ ❗ -
iOSDC Japan 2022 - Unconference #iosdc #unconference ͚ͩ͘͜͜Γൈ͖͍ͨ Try 7:
λΠϚʔ͕ಈ͔ͤΔͳΒೣϑΥϯτͰࠩ͠ସ͑Ε͍͍͡Όͳ͍ -
iOSDC Japan 2022 - Unconference #iosdc #unconference struct ContentView: View
{ var body: some View { Text(Date(), style: .timer) .lineLimit(1) .font(.custom("Runningcat-Regular", size: 200)) .fixedSize(horizontal: true, vertical: false) .frame(width: 120, alignment: .trailing) .clipped() } } in App Try 7: λΠϚʔ͕ಈ͔ͤΔͳΒೣϑΥϯτͰࠩ͠ସ͑Ε͍͍͡Όͳ͍ .lineLimit(1) ͱ . fi xedSize() ͰվߦΛڐ͞ͳ͍Α͏ʹ͢Δ .frame(width: 120, alignment: .trailing) Ͱ෯ΛೣҰඖʹ ͭͭ͠ɺTextΛӈدͤʹ͢Δ .clipped() Ͱ༨ͳೣΛফ͢ -
iOSDC Japan 2022 - Unconference #iosdc #unconference struct ContentView: View
{ var body: some View { Text(Date(), style: .timer) .lineLimit(1) .font(.custom("Runningcat-Regular", size: 200)) .fixedSize(horizontal: true, vertical: false) .frame(width: 120, alignment: .trailing) .clipped() } } in Widget Try 7: λΠϚʔ͕ಈ͔ͤΔͳΒೣϑΥϯτͰࠩ͠ସ͑Ε͍͍͡Όͳ͍ ΟδΣοτͩͱ Text(Date(), style: .timer) ͱ . fi xedSize() ͷ૬ੑ͕ѱ͍Β͘͠ɺText͕ফ͑ͯ͠·͏ ͱʃ͓ʃ͠ʃͯʃͨʃΑʃ͓ʃ͓ʃ͓ʃʂ 💢 -
iOSDC Japan 2022 - Unconference #iosdc #unconference ͍ͭʹΟδΣοτͰೣಈ͖·ͨ͠ʂʂ Try 7:
λΠϚʔ͕ಈ͔ͤΔͳΒೣϑΥϯτͰࠩ͠ସ͑Ε͍͍͡Όͳ͍ Γ·ͨ͠🎉 ༏উ🏆 👑 -
iOSDC Japan 2022 - Unconference #iosdc #unconference in Widget Try
7: λΠϚʔ͕ಈ͔ͤΔͳΒೣϑΥϯτͰࠩ͠ସ͑Ε͍͍͡Όͳ͍ . fi xedSize() Group ͰแΜͰ͔Β͑༗ޮ .clipped() ͞Βʹ Group ͰแΜͰ͔Β͑༗ޮ var body: some View { Group { Group { Text(Date(), style: .timer) .lineLimit(1) .truncationMode(.head) .font(.custom("Runningcat-Regular", size: 120)) .frame(width: 200) } .fixedSize() } .frame(width: 90, alignment: .trailing) .clipped() } -
iOSDC Japan 2022 - Unconference #iosdc #unconference var body: some
View { Group { Group { Text(Date(), style: .timer) .lineLimit(1) .truncationMode(.head) .font(.custom("Runningcat-Regular", size: 120)) .frame(width: 200) } .fixedSize() } .frame(width: 90, alignment: .trailing) .clipped() } in Widget Try 7: λΠϚʔ͕ಈ͔ͤΔͳΒೣϑΥϯτͰࠩ͠ସ͑Ε͍͍͡Όͳ͍ .truncationMode(.head) Ͱ෯͕Γͳ͍ͱ͖ઌ಄͕ ʮ…ʯͰলུ͞ΕΔΑ͏ʹ͓ͯ͘͜͠ͱ͕ॏཁ লུͭͭ͠෯Λݻఆͤ͞ΔͨΊʹɺframe(width: 200) Ͱ ೋจࣈͷ෯Λࢦఆ͢Δ -
iOSDC Japan 2022 - Unconference #iosdc #unconference var body: some
View { Group { Group { Text(Date(), style: .timer) .lineLimit(1) .truncationMode(.head) .font(.custom("Runningcat-Regular", size: 120)) .frame(width: 200) } .fixedSize() } .frame(width: 90, alignment: .trailing) .clipped() } in Widget Try 7: λΠϚʔ͕ಈ͔ͤΔͳΒೣϑΥϯτͰࠩ͠ସ͑Ε͍͍͡Όͳ͍ .clipped() ͢Δલʹ .frame(width: 90, alignment: .trailing) Ͱද͍ࣔͤͨ͞ೣҰඖͷ෯Λ֬อ͢Δ -
iOSDC Japan 2022 - Unconference #iosdc #unconference RunCatͱͯ͠ͷ՝ Έ্ɺίϚૹΓͷִؒ̍ඵͰݻఆ Կ͔ͷঢ়ଶʹԠͯ͡εϐʔυΛม͑Δͱ͍͏͜ͱͰ͖ͳ͍
͔ͯ͜Ε͡ΌΞχϝʔγϣϯ ͱݴ͑ͳ͘ͳ͍ʁ ͏ͬͤ͐ʂ 💢 -
iOSDC Japan 2022 - Unconference #iosdc #unconference RunCatͱͯ͠ͷ՝ Έ্ɺίϚૹΓͷִؒ̍ඵͰݻఆ Կ͔ͷঢ়ଶʹԠͯ͡εϐʔυΛม͑Δͱ͍͏͜ͱͰ͖ͳ͍
ঢ়ଶʹԠͯ͡ೣҎ֎ͷϥϯφʔʹΓସ͑Δ ͍ͬͯΔίϚΞχϝ͚ͩͰͳ͘า͍͍ͯΔίϚΞχϝ༻ҙ͢Δ