有没有办法隐藏苹果手表中的默认活动指标?

时间:2015-05-26 12:14:22

标签: ios swift apple-watch activity-indicator

在我的应用程序中实现自定义活动指示器,默认情况下,Apple watch有活动指示器,我不想显示我怎样才能实现?因为默认活动指示器恰好位于屏幕的中心,但自定义活动指示器稍微下降。第一个是默认和第二个自定义图像。

有没有办法提供自定义框架或隐藏默认活动指示器?

enter image description hereenter image description here

2 个答案:

答案 0 :(得分:2)

不幸的是没有。不存在这样的API。它全部由操作系统控制。

答案 1 :(得分:0)

SwiftUI

enter image description here

import SwiftUI

struct ActivityIndicatorView: View {

    // MARK: - Value
    // MARK: Public
    @Binding var isAnimating: Bool


    // MARK: Private
    private let radius: CGFloat = 10.0
    private let count = 6
    private let interval: TimeInterval = 0.15
    private let minimumOpacity: Double = 0.25
    @State private var opacity: Double = 0

    private let point = { (index: Int, count: Int, radius: CGFloat, frame: CGRect) -> CGPoint in
        let angle   = 2.0 * .pi / Double(count) * Double(index)
        let circleX = radius * cos(CGFloat(angle))
        let circleY = radius * sin(CGFloat(angle))

        return CGPoint(x: circleX + frame.midX, y: circleY + frame.midY)
    }

    private let timer = Timer.publish(every: 6 * 0.15, on: .main, in: .common).autoconnect()     // every = count * interval



    // MARK: - View
    var body: some View {
        GeometryReader { geometry in
            ForEach(0..<self.count) { index in
                Circle()
                    .fill(Color.white)
                    .frame(width: 9.0, height: 9.0)
                    .animation(nil)
                    .opacity(self.opacity <= 0 ? 1.0 * Double(index == 0 ? 6 : index) / Double(self.count) : self.opacity)
                    .position(self.point(index, self.count, self.radius, geometry.frame(in: .local)))
                    .animation(
                       Animation.easeOut(duration: self.minimumOpacity < self.opacity ? 0.3 : 0.4)
                            .repeatCount(1, autoreverses: true)
                            .delay(TimeInterval(index) * self.interval)
                    )
            }
            .onReceive(self.timer) { output in
                self.update()
            }
        }
        .rotationEffect(.degrees(30))
        .opacity(isAnimating == false ? 0 : 1.0)
        .onAppear {
            self.update()
        }
    }



    // MARK: - Function
    // MARK: Private
    private func update() {
        opacity = minimumOpacity < opacity ? minimumOpacity : 1.0

        DispatchQueue.main.asyncAfter(deadline: .now() + 0.38) {
            self.opacity = self.minimumOpacity
        }
    }
}

#if DEBUG
struct ActivityIndicatorView_Previews: PreviewProvider {

    static var previews: some View {
        let view = ActivityIndicatorView(isAnimating: .constant(true))

        return Group {
            view
                .previewDevice("Apple Watch Series 5 - 44mm")

            view
                .previewDevice("Apple Watch Series 4 - 40mm")

            view
                .previewDevice("Apple Watch Series 3 - 42mm")

            view
                .previewDevice("Apple Watch Series 3 - 38mm")
        }
    }
}
#endif