Post

Replies

Boosts

Views

Activity

Setting rounded corners via CAShapeLayer.path looks problematic
class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .white do { let shapeLayer = CAShapeLayer() shapeLayer.frame = CGRect(x: 50, y: 100, width: 200, height: 108) let path = UIBezierPath(roundedRect: shapeLayer.bounds, cornerRadius: 36) shapeLayer.path = path.cgPath shapeLayer.fillColor = UIColor.orange.cgColor view.layer.addSublayer(shapeLayer) } do { let layer = CALayer() layer.backgroundColor = UIColor.blue.cgColor layer.cornerRadius = 36 layer.frame = CGRect(x: 50, y: 300, width: 200, height: 108) view.layer.addSublayer(layer) } } } The corner radius is set to 36 through CAShapeLayer, but the actual effect is larger than 36, close to half of the height. Setting it through CALayer is fine Can anyone explain it to me? Thank you
1
0
196
1w
In WidgetKit, how to refresh automatically after the request fails?
I tried not calling completion in gettimeline. After about 40s, the system will call gettimeline again, but after 5 times, if completion is still not called, the widget refresh will be disordered. The set Timeline does not take effect, and the active call to WidgetCenter.shared.reloadAllTimelines() does not take effect. So now I didn't find a proper way to auto refresh. sample code: struct Provider: IntentTimelineProvider { static var count = 0 func placeholder(in context: Context) -> SimpleEntry { return SimpleEntry(date: Date(), name: "") } func getSnapshot(for configuration: OpenWidgetConfigIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) { let entry = SimpleEntry(date: Date(), name: "") completion(entry) } func getTimeline(for configuration: OpenWidgetConfigIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) { if Self.count < 4 { Self.count = Self.count + 1 return } else { Self.count = 0 } doTimeLineCompletion(name: "Sir Isaac Newton", image: nil, completion: completion) } func doTimeLineCompletion(name: String, image: UIImage?, completion: @escaping (Timeline<Entry>) -> ()) { var entries: [SimpleEntry] = [] var entry = SimpleEntry(date: Date(), name: name) entries.append(entry) let timeline = Timeline(entries: entries, policy: .after(Date().addingTimeInterval(TimeInterval(300)))) completion(timeline) } } struct SimpleEntry: TimelineEntry { let date: Date let name: String }
0
0
564
Jul ’22