Post

Replies

Boosts

Views

Activity

CIMotionBlur broken in iOS16 ?
The following code just does not behaves the same way previous to iOS 16 and with iOS 16. The blur effect does not seem to work correctly in iOS 16. class GameScene: SKScene { override func didMove(to view: SKView) { let shapeNode = SKShapeNode(circleOfRadius: 30) shapeNode.fillColor = .green shapeNode.strokeColor = .clear addChild(shapeNode) let blurredShapeNode = SKShapeNode(circleOfRadius: 30) blurredShapeNode.fillColor = .red blurredShapeNode.strokeColor = .clear let effectNode = SKEffectNode() addChild(effectNode) effectNode.addChild(blurredShapeNode) let blurAngle = NSNumber(value: 0) effectNode.filter = CIFilter( name: "CIMotionBlur", parameters: [kCIInputRadiusKey: 30, kCIInputAngleKey: blurAngle]) } }
1
0
966
Oct ’22
Use embedded framework in WatchKit extension
I have a project of an iOS app with an embedded framework called TotoKit with some model classes. Now I've added a new target with the template "WatchApp for iOS App" to my project. When I try to do "import TotoKit" from the newly created WatchKit extension, no such module is found. What do I have to do ? I have tried without success to: add one dependencies to TotoKi in BuildPhase of the extension target add AppleWatch in Deployment/Target Device Families of the TotoKit target Thanks,
0
0
730
Jan ’22
UIDatePickerStyle.compact does not work on 13.7
The Apple documentation says that .compact style of a UIDatePicker is available from iOS 13.4. When I launch in the simulator in iOS 13.7 my app with deployment target to iOS 13.4 and use a UIDatePicker it is displayed a the classic wheel. That does not sound normal according to documentation! Any idea?
1
0
871
Nov ’20
Format a date but without the year
I want to display the long version of a date BUT WITHOUT the yearWith:let dateFormatter = DateFormatter() dateFormatter.dateStyle = .full dateFormatter.timeStyle = .none dateFormatter.doesRelativeDateFormatting = true dateFormatter.locale = Calendar.current.locale if let inPast = Calendar.current.date(byAdding: .day, value: -30, to: Date()) { let text = dateFormatter.string(from: inPast) }The output is "Wednesday, April 15, 2020" and I want to have "Wednesday, April 15"
5
0
2.2k
May ’20
@NSManaged crash for a CALayer animation
I've defined a custom layer property (used by a custom subclass of UIView) that I animate with a UIView.animated (or UIView.animateKeyframes). I have some strange crashes arround the property.: -[__NSCFType doubleValue]: unrecognized selector sent to instanceNote that when used on a small sample project the animation/view never crash but crash in my main project. Any advice of what I should check? Xcode project settings seems the same. Something else in code or configuration to check?The full callstack is: 0 CoreFoundation 0x00007fff23e39f0e __exceptionPreprocess + 350 1 libobjc.A.dylib 0x00007fff50ad79b2 objc_exception_throw + 48 2 CoreFoundation 0x00007fff23e5ac34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 3 CoreFoundation 0x00007fff23e3e90c ___forwarding___ + 1436 4 CoreFoundation 0x00007fff23e40bf8 _CF_forwarding_prep_0 + 120 5 QuartzCore 0x00007fff2b53a285 CA_setValueForKey + 557 6 QuartzCore 0x00007fff2b4f1e52 -[CABasicAnimation applyForTime:presentationObject:modelObject:] + 869 7 QuartzCore 0x00007fff2b4b4eb1 _ZN2CA5Layer13layer_at_timeEPNS_11TransactionEdbb + 1023 8 QuartzCore 0x00007fff2b4b4a84 _ZN2CA5Layer17layer_being_drawnEPNS_11TransactionEj + 132 9 QuartzCore 0x00007fff2b4b6671 _ZL16backing_callbackP9CGContextPv + 65 10 QuartzCore 0x00007fff2b379e48 CABackingStoreUpdate_ + 196 11 QuartzCore 0x00007fff2b4b66bd ___ZN2CA5Layer8display_Ev_block_invoke + 53 12 QuartzCore 0x00007fff2b4ad66e -[CALayer _display] + 2026 13 QuartzCore 0x00007fff2b4bfdca _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 520 14 QuartzCore 0x00007fff2b408c84 _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324 15 QuartzCore 0x00007fff2b43c65f _ZN2CA11Transaction6commitEv + 649 16 UIKitCore 0x00007fff48bc155c _UIApplicationFlushRunLoopCATransactionIfTooLate + 104 17 UIKitCore 0x00007fff48c6e5fc __handleEventQueueInternal + 7487 18 UIKitCore 0x00007fff48c64dcb __handleHIDEventFetcherDrain + 88 19 CoreFoundation 0x00007fff23d9deb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 20 CoreFoundation 0x00007fff23d9dddc __CFRunLoopDoSource0 + 76 21 CoreFoundation 0x00007fff23d9d5b4 __CFRunLoopDoSources0 + 180 22 CoreFoundation 0x00007fff23d981ae __CFRunLoopRun + 974 23 CoreFoundation 0x00007fff23d97ac4 CFRunLoopRunSpecific + 404 24 GraphicsServices 0x00007fff38b2fc1a GSEventRunModal + 139 25 UIKitCore 0x00007fff48bc7f80 UIApplicationMain + 1605 26 Calendar2 0x000000010c33400b main + 75 27 libdyld.dylib 0x00007fff519521fd start + 1
0
0
783
May ’20
UIView.animateKeyframes does not last same time as UIView.animate
For a CALayer custom property defined as below, the UIView.animateKeyframes() and a key defined with UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1) does NOT last the same duration as the UIView.animate.UI.animate is correct (10s in my test) but UIView.animateKeyframes is really faster (around 1s to do the job).Any ideas?class AnimatedLayer: CALayer { @NSManaged var progress: CGFloat // Whenever a new presentation layer is created, this function is called and makes a COPY of the object. override init(layer: Any) { super.init(layer: layer) if let layer = layer as? AnimatedLayer { progress = layer.progress } } override init() { super.init() } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } override class func needsDisplay(forKey key: String) -> Bool { if isAnimationKeySupported(key) { return true } return super.needsDisplay(forKey: key) } override func action(forKey event: String) -> CAAction? { if AnimatedLayer.isAnimationKeySupported(event) { let animation = currentAnimationContext(in: self) ?? CABasicAnimation(keyPath: event) animation.keyPath = event if let presentation = presentation() { animation.fromValue = presentation.value(forKeyPath: event) } animation.toValue = nil return animation } return super.action(forKey: event) } private class func isAnimationKeySupported(_ key: String) -> Bool { return key == #keyPath(progress) } private func currentAnimationContext(in layer: CALayer) -> CABasicAnimation? { let animation = action(forKey: #keyPath(backgroundColor)) as? CABasicAnimation return animation?.copy() as? CABasicAnimation } }
0
0
773
May ’20
animated layer property does not work with animateKeyframes
I have added a custom property to a subclass of CALayer in order to animate the layer drawing. The property is correctly animated when I run a UIView.animate but NOT when running UIView.animateKeyframes. Any ideas? The full sample project is available here.This kind of animation works:UIView.animate(withDuration: self.duration, animations: { self.transitionView.progress = 0 })And that DOES NOT works:UIView.animateKeyframes(withDuration: self.duration, delay: 0, options: .calculationModeCubic, animations: { UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1) { self.transitionView.progress = 0 })Here is the layer definition :class AnimatedLayer: CALayer { @NSManaged var progress: CGFloat // Whenever a new presentation layer is created, this function is called and makes a COPY of the object. override init(layer: Any) { super.init(layer: layer) if let layer = layer as? AnimatedLayer { progress = layer.progress } } override init() { super.init() } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } override class func needsDisplay(forKey key: String) -> Bool { if isAnimationKeySupported(key) { return true } return super.needsDisplay(forKey: key) } override func action(forKey event: String) -> CAAction? { if AnimatedLayer.isAnimationKeySupported(event) { // Copy animation context and mutate as needed guard let animation = currentAnimationContext(in: self)?.copy() as? CABasicAnimation else { setNeedsDisplay() return nil } animation.keyPath = event if let presentation = presentation() { animation.fromValue = presentation.value(forKeyPath: event) } animation.toValue = nil return animation } return super.action(forKey: event) } private class func isAnimationKeySupported(_ key: String) -> Bool { return key == #keyPath(progress) } private func currentAnimationContext(in layer: CALayer) -> CABasicAnimation? { /// The UIView animation implementation is private, so to check if the view is animating and /// get its property keys we can use the key "backgroundColor" since its been a property of /// UIView which has been forever and returns a CABasicAnimation. return action(forKey: #keyPath(backgroundColor)) as? CABasicAnimation } }Ands the view code is :class DayTransitionView: UIView { override class var layerClass: AnyClass { return AnimatedLayer.self } var progressLayer: AnimatedLayer { return layer as! AnimatedLayer } @objc dynamic var progress: CGFloat { set { progressLayer.progress = newValue } get { return progressLayer.presentation()?.progress ?? progressLayer.progress } } // if not redefined draw:layer is not called ! override func draw(_ rect: CGRect) { } override func draw(_ layer: CALayer, in ctx: CGContext) { UIGraphicsPushContext(ctx); // background color let backgroundPath: CGPath = UIBezierPath(roundedRect: layer.bounds, byRoundingCorners: [.topLeft, .topRight, .bottomLeft, .bottomRight] , cornerRadii: .zero).cgPath ctx.addPath(backgroundPath) ctx.setFillColor(UIColor.green.cgColor) ctx.closePath() ctx.fillPath() // background color let fillHeight = self.progressive(layer.bounds.origin.y, layer.bounds.origin.y + layer.bounds.size.height) let fillRect = CGRect(x: layer.bounds.origin.x, y: layer.bounds.origin.y + layer.bounds.size.height - fillHeight, width: layer.bounds.size.width, height: fillHeight) let fillPath: CGPath = UIBezierPath(roundedRect: fillRect, byRoundingCorners: [.topLeft, .topRight, .bottomLeft, .bottomRight] , cornerRadii: .zero).cgPath ctx.addPath(fillPath) ctx.setFillColor(UIColor.red.cgColor) ctx.closePath() ctx.fillPath() UIGraphicsPopContext(); } func progressive(_ from: CGFloat, _ to: CGFloat) -> CGFloat { return from + self.progress * (to - from) } }
0
0
1.7k
May ’20
UIStackView with arranged subviews of same size
I want to have 7 views with same width, fixed spacing between views and everything that fit the superview. That sounds easy. I know the solution without UIStackView. I thought UIStackView could be simplier (I do the job programmatically and not in storyboard). The code below does not do the job? What do I miss ?class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() var horizontalViews:[UIView] = [] // 7 views for the stack for _ in 0...6 { let dayView = UIView(frame: .zero) dayView.backgroundColor = .blue horizontalViews.append(dayView) } let stack = UIStackView(arrangedSubviews: horizontalViews) stack.axis = .vertical stack.distribution = .fillEqually stack.spacing = 10 self.view.addSubview(stack) // the left and right of the stack is stucked to the controller view stack.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true stack.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true // vertical size and position of the stack stack.centerYAnchor.constraint(equalTo: self.view.centerYAnchor).isActive = true stack.heightAnchor.constraint(equalToConstant: 50).isActive = true } }
0
0
717
Mar ’20
extract detailed heart rate of a workout
I want to access the most detailled list of heartrate for a workout (from 5:26PM to 5:58PM). On iOS 13, it sounds easy with the code that print 385 heartrates:if #available(iOS 13.0, *) { var index = 1 let quantityType = HKQuantityType.quantityType(forIdentifier: .heartRate)! let predicate = HKQuery.predicateForSamples(withStart: self.workout.startDate, end: self.workout.endDate, options: [.strictStartDate]) let heartRateUnit = HKUnit.count().unitDivided(by: HKUnit.minute()) let query2 = HKQuantitySeriesSampleQuery(quantityType: quantityType, predicate: predicate) { (query, quantity, dateInterval, sample, done, error) in let rate = quantity!.doubleValue(for: heartRateUnit) print("#\(index) \(rate)") index += 1 } HealthKitManager.shared.healthStore.execute(query2) }But on iOS 12 and lower, with the followig code, I've got only 4 samples :2019-02-06 4:26:32 PM +0000 to 2019-02-06 4:26:32 PM +0000 : 138.039142709874032019-02-06 4:36:27 PM +0000 to 2019-02-06 4:36:27 PM +0000 : 168.304179434091822019-02-06 4:46:33 PM +0000 to 2019-02-06 4:46:33 PM +0000 : 177.633914397371142019-02-06 4:56:25 PM +0000 to 2019-02-06 4:56:25 PM +0000 : 167.2611138237847let heartRateQuery = HKSampleQuery( sampleType: HKQuantityType.quantityType(forIdentifier: .heartRate)!, predicate: HKQuery.predicateForSamples(withStart: startDate, end: endDate, options: [.strictStartDate]), limit: HKObjectQueryNoLimit, sortDescriptors: [ NSSortDescriptor(key: HKSampleSortIdentifierStartDate, ascending: true) ]) { (_: HKSampleQuery, results: [HKSample]?, error: Error?) in let heartRateUnit = HKUnit.count().unitDivided(by: HKUnit.minute()) for result in results! { if let sample:HKQuantitySample = result as? HKQuantitySample { let rate = sample.quantity.doubleValue(for: heartRateUnit) print("\(sample.startDate) to \(sample.startDate) : \(rate)") } }How can I get more samples with iOS < 13 ? What do I miss ?
2
0
959
Dec ’19