Core Animation

RSS for tag

Render, compose, and animate visual elements using Core Animation.

Core Animation Documentation

Posts under Core Animation tag

37 Posts
Sort by:
Post not yet marked as solved
0 Replies
122 Views
I have an app that displays an instrument dial that looks a bit like a speedometer or voltmeter with a circular face and a pointer. When operating, it updates perhaps once or twice a second, possibly more (it's triggered by data updates received by the network), using a CABasicAnimation as shown in the code below. But it's also quite possible that the dial is not visible to the user, for instance, if another tab view is active, or the dial is scrolled off-screen. What happens to animations on views/layers that aren't visible, do they just get discarded? I'm wondering if I should add a check of some sort in my code to minimize unnecessary performance hits. If so, how would I check if a UIView/CALayer is user-visible? I'm assuming animations are "efficient" in the way I imagine but you know what they say about assuming... func updateDialWithAnimation(degrees: CGFloat) { let radians = degrees * CGFloat.pi / 180 let animation = CABasicAnimation() animation.keyPath = "transform.rotation.z" animation.fromValue = CGFloat(angle.value) * CGFloat.pi / 180 animation.toValue = radians animation.duration = 0.33 angleLabel.text = String(Float(degrees)) angle.value = Float(degrees) // needle is a subclass of UIView needle.layer.add(animation, forKey: "basic") needle.layer.transform = CATransform3DMakeRotation(radians, 0, 0, 1) }
Posted
by tgherzog.
Last updated
.
Post not yet marked as solved
2 Replies
454 Views
In the iOS app I'm developing, I've noticed that since upgrading to iOS 17 (Xcode 15.1), crashes of this type occur frequently. The crashes are random and can't be reliably reproduced. Below is a typical crash report: CrashReporter Key: fd24cf14a51d73ebfc1852cccb1b8d50822b247c Hardware Model: iPhone11,2 Process: MyApp [89057] Path: /private/var/containers/Bundle/Application/06B982E0-B818-48A9-B2D1-F28999EC3BC0/MyApp.app/MyApp Identifier: com.company.MyApp Version: 2.0.0 (72) Code Type: ARM-64 (Native) Role: Foreground Parent Process: launchd [1] Coalition: com.company.MyApp [4659] Date/Time: 2024-03-24 14:50:46.3982 +0800 Launch Time: 2024-03-24 14:38:38.1438 +0800 OS Version: iPhone OS 17.3.1 (21D61) Release Type: User Baseband Version: 6.00.00 Report Version: 104 Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x000000018c44e838 Termination Reason: SIGNAL 5 Trace/BPT trap: 5 Terminating Process: exc handler [89057] Triggered by Thread: 0 Kernel Triage: VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 libobjc.A.dylib 0x18c44e838 object_getClass + 48 1 Foundation 0x1930807b4 _NSKeyValueObservationInfoGetObservances + 264 2 Foundation 0x19307fc7c NSKeyValueWillChangeWithPerThreadPendingNotifications + 232 3 QuartzCore 0x19572f14c CAAnimation_setter(CAAnimation*, unsigned int, _CAValueType, void const*) + 128 4 QuartzCore 0x19574a6b4 -[CAAnimation setBeginTime:] + 52 5 QuartzCore 0x1957485b4 CA::Layer::commit_animations(CA::Transaction*, double (*)(CA::Layer*, double, void*), void (*)(CA::Layer*, CA::Render::Animation*, void*), void (*)(CA::Layer*, __CFString const*, void*), CA::Render::TimingList* (*)(CA::Layer*, void*), void*) + 740 6 QuartzCore 0x195700bf0 invocation function for block in CA::Context::commit_transaction(CA::Transaction*, double, double*) + 148 7 QuartzCore 0x195700af8 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 368 8-14QuartzCore 0x195700a84 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 15 QuartzCore 0x195745248 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 11192 16 QuartzCore 0x19573bb80 CA::Transaction::commit() + 648 17 QuartzCore 0x19573b828 CA::Transaction::flush_as_runloop_observer(bool) + 88 18 CoreFoundation 0x1940ff7bc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36 19 CoreFoundation 0x1940fe1c4 __CFRunLoopDoObservers + 548 20 CoreFoundation 0x1940fd8e0 __CFRunLoopRun + 1028 21 CoreFoundation 0x1940fd3f8 CFRunLoopRunSpecific + 608 22 GraphicsServices 0x1d768b4f8 GSEventRunModal + 164 23 UIKitCore 0x1965238a0 -[UIApplication _run] + 888 24 UIKitCore 0x196522edc UIApplicationMain + 340 25 MyApp 0x102c1f014 main + 140 26 dyld 0x1b6e52dcc start + 2240 By looking up information on the Exception Type and Termination Reason, I found that Apple officially mentions that EXC_BREAKPOINT (SIGTRAP) SIGNAL 5 Trace/BPT trap: 5 could be caused by Swift runtime error crashing mechanisms, mainly due to: If you use the ! operator to force unwrap an optional value that’s nil, or if you force a type downcast that fails with the as! operator, the Swift runtime catches these errors and intentionally crashes the app. For details, see the link: https://developer.apple.com/documentation/xcode/addressing-crashes-from-swift-runtime-errors My project is a mix of Objc+Swift compilation, the crash usually occurs after a button click triggers a change in UIView properties, mostly related to layout. All Swift code in the project is unrelated to this type of UI. So, I speculate that it might not be related to Swift runtime errors, but I'm unsure what other possible causes could lead to the aforementioned crash. A common denominator in all similar crash reports is that they occur on the main thread during system framework function calls, All show multiple instances of VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter CA::Layer::commit_if_needed is always invoked. I noticed many crashes relate to CALayer setting properties internally calling CAAnimation, so I added: @implementation CALayer (Animation) /// Prevent crashes + (void)disableAnimation:(VoidBlock)block{ [CATransaction begin]; [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; block(); [CATransaction commit]; } @end Using [CALayer disableAnimation:^{view.layer.someProperty = someValue;}] to disable animations has prevented some crashes, but I'm powerless in situations like the stack trace above, where all calls are made by system frameworks. I've also noticed other similar crash issues on forums: EXC_BREAKPOINT - libobjc.A.dylib object_getClass Crash on the main thread. The author experienced this issue after iOS 16 and iOS 17, with very similar stack information to mine. I suspect other potential causes might include: Whether it's related to KVO in UI code not being correctly released. Whether it involves calls to GPU resources from other threads. I've rewritten most of the code to ensure no GPU-related image operations occur on other threads during CoreAnimation runtime. Whether it's related to high memory usage and peak virtual memory. My app is related to image processing, and opening 4K photos for processing typically consumes more than 500MB of memory. If you've encountered similar situations or can help identify potential causes, please advise. Many thanks!
Posted Last updated
.
Post not yet marked as solved
0 Replies
146 Views
Hi. Can anyone who's into cosmology give hints as to how I might depict and animate dark matter for the VisionPro?
Posted
by Jeqhe.
Last updated
.
Post not yet marked as solved
1 Replies
285 Views
To reproduce this bug: Set the .large navigation title in a View (which is in a NavigationView) Add the .searchable modifier And add the .refreshable modifier over a scroll view for example Drag the pull to refresh Actual result: The navigation bar is blinking and jumping to the top without smooth animation Expected result: Navigation bar behaves expectedly as usual I noticed if we use the .inline navigation title style or remove the .searchable modifier it work correctly
Posted Last updated
.
Post not yet marked as solved
11 Replies
1.7k Views
I've started seeing several users getting an app crash that I've been unable to find the root cause for so far. I've tried running the app in release build with address sanitizer and zombie objects checks enabled but have been unable to reproduce it. It only occurs for iOS 17 users. Any ideas on how I can troubleshoot this? Crashed: com.apple.main-thread EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000 Crashed: com.apple.main-thread 0 libsystem_platform.dylib 0xed4 _platform_memmove + 52 1 QuartzCore 0x137120 CA::Render::InterpolatedFunction::encode(CA::Render::Encoder*) const + 248 2 QuartzCore 0x136f40 CA::Render::GradientLayer::encode(CA::Render::Encoder*) const + 44 3 QuartzCore 0x2e384 CA::Render::Layer::encode(CA::Render::Encoder*) const + 284 4 QuartzCore 0x2e224 CA::Render::encode_set_object(CA::Render::Encoder*, unsigned long, unsigned int, CA::Render::Object*, unsigned int) + 196 5 QuartzCore 0x2b654 invocation function for block in CA::Context::commit_transaction(CA::Transaction*, double, double*) + 244 6 QuartzCore 0x2b4fc CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 368 7 QuartzCore 0x2b488 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 8 QuartzCore 0x2b4bc CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 304 9 QuartzCore 0x2b488 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 10 QuartzCore 0x2b488 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 11 QuartzCore 0x2b488 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 12 QuartzCore 0x2b488 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 13 QuartzCore 0x2b488 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 14 QuartzCore 0x2b488 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 15 QuartzCore 0x2b488 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 16 QuartzCore 0x2b488 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 17 QuartzCore 0x2b488 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 18 QuartzCore 0x2b488 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 19 QuartzCore 0x6fc60 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 11192 20 QuartzCore 0x66574 CA::Transaction::commit() + 648 21 UIKitCore 0x31b5ec __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 36 22 CoreFoundation 0x373a8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 28 23 CoreFoundation 0x35b9c __CFRunLoopDoBlocks + 356 24 CoreFoundation 0x33a9c __CFRunLoopRun + 848 25 CoreFoundation 0x33668 CFRunLoopRunSpecific + 608 26 GraphicsServices 0x35ec GSEventRunModal + 164 27 UIKitCore 0x22c2b4 -[UIApplication _run] + 888 28 UIKitCore 0x22b8f0 UIApplicationMain + 340 29 Coach 0x799d8 main + 14 (main.m:14) 30 ??? 0x1abefadcc (Missing)
Posted
by mdhorda.
Last updated
.
Post not yet marked as solved
1 Replies
625 Views
I'm trying to animate a shape (e.g. a circle) to follow a custom path, and struggling to find the best way of doing this. I've had a look at the animation options from SwiftUI, UIKit and SpriteKit and all seem very limited in what paths you can provide. Given the complexity of my path, I was hoping there'd be a way of providing a set of coordinates in some input file and have the shape follow that, but maybe that's too ambitious. I was wondering if this were even possible, and assuming not, if there were other options I could consider.
Posted Last updated
.
Post not yet marked as solved
1 Replies
307 Views
I have a navigation controller with two VCs. One VC is pushed onto the NavController, the other is presented on top of the NavController. The presented VC has a relatively complex animation involving a CAEmitter -> Animate birth rate down -> Fade out -> Remove. The pushed VC has an 'inputAccessoryView' and can become first responder. The expected behavior is open presented VC -> Emitter Emits pretty pictures -> emitter stops gracefully. The animation works perfectly. UNLESS I open pushed VC -> Leave -> go to presented VC. In this case when I open the presented VC the emitter emits pretty pictures -> they never stop. (Please do not ask me how long it took to figure this much out 🤬😔) The animation code in question is: let animation = CAKeyframeAnimation(keyPath: #keyPath(CAEmitterLayer.birthRate)) animation.duration = 1 animation.timingFunction = CAMediaTimingFunction(name: .easeIn) animation.values = [1, 0 , 0] animation.keyTimes = [0, 0.5, 1] animation.fillMode = .forwards animation.isRemovedOnCompletion = false emitter.beginTime = CACurrentMediaTime() let now = Date() CATransaction.begin() CATransaction.setCompletionBlock { [weak self] in print("fade beginning -- delta: \(Date().timeIntervalSince(now))") let transition = CATransition() transition.delegate = self transition.type = .fade transition.duration = 1 transition.timingFunction = CAMediaTimingFunction(name: .easeOut) transition.setValue(emitter, forKey: kKey) transition.isRemovedOnCompletion = false emitter.add(transition, forKey: nil) emitter.opacity = 0 } emitter.add(animation, forKey: nil) CATransaction.commit() The delegate method is: extension PresentedVC: CAAnimationDelegate { func animationDidStop(_ anim: CAAnimation, finished flag: Bool) { if let emitter = anim.value(forKey: kKey) as? CALayer { emitter.removeAllAnimations() emitter.removeFromSuperlayer() } else { } } } Here is the pushed VC: class PushedVC: UIViewController { override var canBecomeFirstResponder: Bool { return true } override var canResignFirstResponder: Bool { return true } override var inputAccessoryView: UIView? { return UIView() } } So to reiterate - If I push pushedVC onto the navController, pop it, present PresentedVC the emitters emit, but then the call to emitter.add(animation, forKey: nil) is essentially ignored. The emitter just keeps emitting. Here are some sample happy print statements from the completion block: fade beginning -- delta: 1.016232967376709 fade beginning -- delta: 1.0033869743347168 fade beginning -- delta: 1.0054619312286377 fade beginning -- delta: 1.0080779790878296 fade beginning -- delta: 1.0088880062103271 fade beginning -- delta: 0.9923020601272583 fade beginning -- delta: 0.99943196773529 Here are my findings: The issue presents only when the pushed VC has an inputAccessoryView AND canBecomeFirstResponder is true It does not matter if the inputAccessoryView is UIKit or custom, has size, is visible, or anything. When I dismiss PresentedVC the animation is completed and the print statements show. Here are some unhappy print examples: fade beginning -- delta: 5.003802061080933 fade beginning -- delta: 5.219511032104492 fade beginning -- delta: 5.73025906085968 fade beginning -- delta: 4.330522060394287 fade beginning -- delta: 4.786169052124023 CATransaction.flush() does not fix anything Removing the entire CATransaction block and just calling emitter.add(animation, forKey: nil) similarly does nothing - the birth rate decrease animation does not happen I am having trouble creating a simple demo project where the issue is reproducible (it is 100% reproducible in my code, the entirety of which I'm not going to link here) so I think getting a "solution" is unrealistic. What I would love is if anyone had any suggestions on where else to look? Any ways to debug CAAnimation? I think if I can solve the last bullet - emitter.add(animation, forKey: nil) called w/o a CATransaction - I can break this whole thing. Why would a CAAnimation added directly to the layer which is visible and doing stuff refuse to run?
Posted Last updated
.
Post not yet marked as solved
1 Replies
359 Views
Hello everyone, I'm working on a macOS application and encountering an issue related to multi-screen setups. My application includes an animation in the menu bar, and it works perfectly on the primary screen. However, I want this animation to stop or not appear when the app is being used on a secondary monitor(non-focused monitor). (for cpu related problem, when it's 3 monitor -> x3 cpu with x3 animation objects) I've tried a few approaches to detect when the application is being used on a secondary screen and then stop the animation, but so far, I haven't had any success. The main challenge seems to be accurately determining the screen where the app is actively being used and controlling the animation accordingly. Has anyone faced a similar issue or have suggestions on how to effectively stop or prevent the menu bar animation from running on a secondary screen? Any guidance or insights would be greatly appreciated. Thank you in advance for your help!
Posted
by hhajime.
Last updated
.
Post not yet marked as solved
6 Replies
874 Views
Having an issue with crashes on iOS 16 and iOS 17 devices. App works and will appear to operate normally. However after a while the app will crash with a EXC_BREAKPOINT on libobjc.A.dylib object_getClass. The root cause seems to be something related to UIViews/Core Animation, I think. However the root crash trigger seems to be a half a dozen different triggers from the UI on main thread. It also only triggers on release builds, or the dev builds take a lot longer to trigger to the point it's very difficult to reproduce. Here are some examples of the crashes occurring. Crashed: com.apple.main-thread 0 libobjc.A.dylib 0xe838 object_getClass + 48 1 Foundation 0x1c854 _NSKeyValueObservationInfoGetObservances + 264 2 Foundation 0x1bd1c NSKeyValueWillChangeWithPerThreadPendingNotifications + 232 3 QuartzCore 0x59408 CAAnimation_setter(CAAnimation*, unsigned int, _CAValueType, void const*) + 128 4 QuartzCore 0x749b4 -[CAAnimation setBeginTime:] + 52 5 QuartzCore 0x728b4 CA::Layer::commit_animations(CA::Transaction*, double (*)(CA::Layer*, double, void*), void (*)(CA::Layer*, CA::Render::Animation*, void*), void (*)(CA::Layer*, __CFString const*, void*), CA::Render::TimingList* (*)(CA::Layer*, void*), void*) + 740 6 QuartzCore 0x2aeac invocation function for block in CA::Context::commit_transaction(CA::Transaction*, double, double*) + 148 7 QuartzCore 0x2adb4 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 368 8 QuartzCore 0x2ad40 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 9 QuartzCore 0x2ad40 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 10 QuartzCore 0x2ad40 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 11 QuartzCore 0x2ad40 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 12 QuartzCore 0x2ad40 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 13 QuartzCore 0x2ad40 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 14 QuartzCore 0x2ad40 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 15 QuartzCore 0x2ad40 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 16 QuartzCore 0x2ad40 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 17 QuartzCore 0x2ad40 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 252 18 QuartzCore 0x6f548 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 11192 19 QuartzCore 0x65e3c CA::Transaction::commit() + 648 20 UIKitCore 0x924cc _afterCACommitHandler + 84 21 CoreFoundation 0x3583c __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36 22 CoreFoundation 0x34244 __CFRunLoopDoObservers + 548 23 CoreFoundation 0x33960 __CFRunLoopRun + 1028 24 CoreFoundation 0x33478 CFRunLoopRunSpecific + 608 25 GraphicsServices 0x34f8 GSEventRunModal + 164 26 UIKitCore 0x22c62c -[UIApplication _run] + 888 27 UIKitCore 0x22bc68 UIApplicationMain + 340 0 libobjc.A.dylib 0x5d94 object_getClass + 48 1 Foundation 0xadb8 _NSKeyValueObservationInfoGetObservances + 248 2 Foundation 0x3f670 NSKeyValueWillChangeWithPerThreadPendingNotifications + 232 3 QuartzCore 0xbb18 CAAnimation_setter(CAAnimation*, unsigned int, _CAValueType, void const*) + 128 4 QuartzCore 0xcc14 -[CAPropertyAnimation setKeyPath:] + 52 5 QuartzCore 0xcbc0 +[CAPropertyAnimation animationWithKeyPath:] + 36 6 UIKitCore 0xc89fb0 -[UIMorphingLabel animateGlyph:toScale:delay:] + 308 7 UIKitCore 0xc8a1fc -[UIMorphingLabel animateShowGlyph:alpha:alphaDuration:delay:] + 196 8 UIKitCore 0xc8b3f0 -[UIMorphingLabel animateSubstitutionAlignmentHunkAtIndex:] + 1068 9 UIKitCore 0x42cd84 -[UIMorphingLabel animateGlyphs] + 276 10 UIKitCore 0xa374 -[UIMorphingLabel layoutSubviews] + 368 11 UIKitCore 0x4420 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1992 12 QuartzCore 0x9f30 CA::Layer::layout_if_needed(CA::Transaction*) + 500 13 QuartzCore 0x1d4ac CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 148 14 QuartzCore 0x2e8d8 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 444 15 QuartzCore 0x5de80 CA::Transaction::commit() + 648 16 QuartzCore 0x47df0 CA::Transaction::flush_as_runloop_observer(bool) + 88 17 CoreFoundation 0x90234 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36 18 CoreFoundation 0x1a410 __CFRunLoopDoObservers + 532 19 CoreFoundation 0x7a19c __CFRunLoopRun + 1028 20 CoreFoundation 0x7f3ec CFRunLoopRunSpecific + 612 21 GraphicsServices 0x135c GSEventRunModal + 164 22 UIKitCore 0x39cf58 -[UIApplication _run] + 888 23 UIKitCore 0x39cbbc UIApplicationMain + 340 I'm at a loss, I'm clearly doing something wrong in the UIView/Core Animation side of things. Would be very grateful for anyone who can point me in the right direction.
Posted
by obriena.
Last updated
.
Post not yet marked as solved
2 Replies
487 Views
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread. I have been experiencing frequent crashes on iOS 17 and above recently, and I'm having trouble pinpointing the source of the crashes. The crash logs provide no information about the specific location of the crashes. Is there any workaround or solution to identify and resolve this issue? Please find attached the crash logs below
Posted
by vimal07.
Last updated
.
Post not yet marked as solved
1 Replies
780 Views
I'm working on a SwiftUI project where I use a .sheet modifier to present a bottom drawer with two detent sizes: .medium and .large. The drawer contains a button that toggles its size between these two states. This part works as expected. However, I'm facing an animation issue when I set a non-default background color to the sheet. Here's the simplified code for context: struct ContentView: View { @State private var selectedDetent: PresentationDetent = .medium var body: some View { VStack {} .sheet(isPresented: .constant(true)) { Button("Press Me") { selectedDetent = selectedDetent == .medium ? .large : .medium } .presentationBackground(.gray) .presentationDetents([.medium, .large], selection: $selectedDetent) } } } The issue arises when I try to set a background color using .presentationBackground(.gray) (or any color, even white). Instead of the expected behavior when pressing the button (where the upper part of the sheet closes, and the bottom part stays attached to the screen bottom), the sheet momentarily turns into a square in the middle of the screen before moving down to the .medium position. As soon as I remove the.presentationBackground(.gray) line, it works as expected: I tried several approaches, such as: Using a custom background view. Explicitly specifying animations. Adjusting view hierarchy and layering. Unfortunately, none of these solutions worked. The issue persists with any color. It seems like a bug or limitation in SwiftUI's handling of sheet animations with custom backgrounds. Has anyone else encountered this issue, or does anyone have a workaround or solution?
Posted
by Flict.
Last updated
.
Post not yet marked as solved
0 Replies
327 Views
Our DJ application Mixxx renders scrolling waveforms with 60 Hz. This looks perfectly smooth on an older 2015 MacBook Pro. However it looks jittery on a new M1 device with "ProMotion" enabled. Selecting 60 Hz fixes the issue. We are looking for a way to tell macOS that it can expect 60 Hz renderings from Mixxx and must not display them early (at 120 Hz) even if the pictures are ready. The alternative would be to read out the display settings and ask the user to select 60 Hz. Is there an API to: hint the display diver that we render with 60 Hz read out the refresh rate settings?
Posted
by daschuer.
Last updated
.
Post not yet marked as solved
1 Replies
543 Views
I'm having issues animating views inside a ForEach list that's inside a border. Here's my code: struct ContentView: View { @State var showNewMethodOptions = false var body: some View { VStack { Button { showNewMethodOptions.toggle() } label: { HStack { Image(systemName: showNewMethodOptions ? "chevron.up" : "plus") .resizable() .scaledToFit() .frame(width: 32) .foregroundColor(.blue) Text("Add new payment method") .foregroundColor(.gray) .padding(.leading, 6) Spacer() } .padding(.horizontal) .padding(.top, 20) .padding(.bottom, showNewMethodOptions ? 10 : 20) } if showNewMethodOptions { ForEach(PaymentMethodType.allCases) { method in NavigationLink { } label: { ZStack(alignment: .center) { RoundedRectangle(cornerRadius: 5) .stroke(.blue) Text(method.rawValue) .font(.title3) .foregroundColor(.gray) } .frame(height: 45.0) .background() .padding(.horizontal) .padding(.vertical, 5) .transition(.slide) } } } } .animation(.spring, value: showNewMethodOptions) .padding(.bottom, showNewMethodOptions ? 16 : 0) .padding(.horizontal) .overlay( RoundedRectangle(cornerRadius: 4) .stroke(.gray, lineWidth: 1) .padding(.vertical, 4) .padding(.horizontal) ) } } enum PaymentMethodType: String, CaseIterable, Identifiable { var id: Self { return self } case checking = "Checking" case savings = "Savings" case creditOrDebitCard = "Card" } When the animation happens, the "add a new payment method" HStack animates nicely enough, but the payment method options fade in while it's still sliding up, which doesn't look great because it looks like everything's on top of each other. The options also don't seem to follow the transition animation I apply to them - it's always just a fade. Is there a way to get these elements to animate together?
Posted
by KBartlett.
Last updated
.
Post not yet marked as solved
0 Replies
470 Views
In UIKit/Core Animation, I can create a CABasicAnimation that lets me animate changes to the Path in a CAShapeLayer. As long as the new path has the same number of control points as the previous path, Core Animation creates a smooth animation of the changes. It's also possible to animate things like the start and end of the stroke, but I'm talking about arbitrary changes to the path. In SwiftUI, it's pretty easy to animate the stroke so that it looks like it's being drawn by a pen. I'm not talking about that. Say I have a closed path with N vertexes and some of the vertexes are connected with straight lines, while others are connected by quadratic or cubic Bézier curves. I want to move the control points around in arbitrary ways, and change the control points of the Bézier curves. I have a simple Storyboard based project on Github that creates closed N-sided polygons with either rounded or sharp corners, it manages an array of PolygonPoint structs that look like this: public struct PolygonPoint { let point: CGPoint let isRounded: Bool let customCornerRadius: CGFloat? init(point: CGPoint, isRounded: Bool, customCornerRadius: CGFloat? = nil) { self.point = point self.isRounded = isRounded self.customCornerRadius = customCornerRadius } init(previousPoint: PolygonPoint, isRounded: Bool) { self.init(point: previousPoint.point, isRounded: isRounded, customCornerRadius: previousPoint.customCornerRadius) } } The sample app builds a square out of an array of PolygonPoints, and then presents 4 swtiches that controls whether each vertex is rounded or not. It builds a polygon using the CGPath addArc(tangent1End:tangent2End:radius:transform:) function, with a 0 radius for sharp corners and a non-zero corner radius for rounded corners. It wraps changes to the path in a CABasicAnimation, and the result is a simple animation. The project can be found on Github here: RoundedConerPolygon project As a learning exercise, I'd like to convert this project to SwiftUI. The Swift/UIKit project creates CGPaths, and there is an initializer for the Swift Path object that takes a CGPath, so that part is easy. However, SwiftUI wants to observe changes to a simple scalar, or to some sort of animatableData. I've tried to make my PolygonPoint struct conform to VectorArithmetic, but no joy. My attempt is here: RoundedCornerPolygonSwiftUI This seems like it should be easy, but I can't figure out how to make it work. Is there a way to have SwiftUI animate changes to a Path's underlying CGPath like you can in UIKit? I could probably wrap a UIKIt custom view in SwiftUI and do it that way, but I'm trying to learn how to do it "The SwifTUI way."
Posted Last updated
.
Post not yet marked as solved
0 Replies
477 Views
This is verified to be a framework bug (occurs on Mac Catalyst but not iOS or iPadOS), and it seems the culprit is AVVideoCompositionCoreAnimationTool? /// Exports a video with the target animating. func exportVideo() { let destinationURL = createExportFileURL(from: Date()) guard let videoURL = Bundle.main.url(forResource: "black_video", withExtension: "mp4") else { delegate?.exporterDidFailExporting(exporter: self) print("Can't find video") return } // Initialize the video asset let asset = AVURLAsset(url: videoURL, options: [AVURLAssetPreferPreciseDurationAndTimingKey: true]) guard let assetVideoTrack: AVAssetTrack = asset.tracks(withMediaType: AVMediaType.video).first, let assetAudioTrack: AVAssetTrack = asset.tracks(withMediaType: AVMediaType.audio).first else { return } let composition = AVMutableComposition() guard let videoCompTrack = composition.addMutableTrack(withMediaType: AVMediaType.video, preferredTrackID: Int32(kCMPersistentTrackID_Invalid)), let audioCompTrack = composition.addMutableTrack(withMediaType: AVMediaType.audio, preferredTrackID: Int32(kCMPersistentTrackID_Invalid)) else { return } videoCompTrack.preferredTransform = assetVideoTrack.preferredTransform // Get the duration let videoDuration = asset.duration.seconds // Get the video rect let videoSize = assetVideoTrack.naturalSize.applying(assetVideoTrack.preferredTransform) let videoRect = CGRect(origin: .zero, size: videoSize) // Initialize the target layers and animations animationLayers = TargetView.initTargetViewAndAnimations(atPoint: CGPoint(x: videoRect.midX, y: videoRect.midY), atSecondsIntoVideo: 2, videoRect: videoRect) // Set the playback speed let duration = CMTime(seconds: videoDuration, preferredTimescale: CMTimeScale(600)) let appliedRange = CMTimeRange(start: .zero, end: duration) videoCompTrack.scaleTimeRange(appliedRange, toDuration: duration) audioCompTrack.scaleTimeRange(appliedRange, toDuration: duration) // Create the video layer. let videolayer = CALayer() videolayer.frame = CGRect(origin: .zero, size: videoSize) // Create the parent layer. let parentlayer = CALayer() parentlayer.frame = CGRect(origin: .zero, size: videoSize) parentlayer.addSublayer(videolayer) let times = timesForEvent(startTime: 0.1, endTime: duration.seconds - 0.01) let timeRangeForCurrentSlice = times.timeRange // Insert the relevant video track segment do { try videoCompTrack.insertTimeRange(timeRangeForCurrentSlice, of: assetVideoTrack, at: .zero) try audioCompTrack.insertTimeRange(timeRangeForCurrentSlice, of: assetAudioTrack, at: .zero) } catch let compError { print("TrimVideo: error during composition: \(compError)") delegate?.exporterDidFailExporting(exporter: self) return } // Add all the non-nil animation layers to be exported. for layer in animationLayers.compactMap({ $0 }) { parentlayer.addSublayer(layer) } // Configure the layer composition. let layerComposition = AVMutableVideoComposition() layerComposition.frameDuration = CMTimeMake(value: 1, timescale: 30) layerComposition.renderSize = videoSize layerComposition.animationTool = AVVideoCompositionCoreAnimationTool( postProcessingAsVideoLayer: videolayer, in: parentlayer) let instructions = initVideoCompositionInstructions( videoCompositionTrack: videoCompTrack, assetVideoTrack: assetVideoTrack) layerComposition.instructions = instructions // Creates the export session and exports the video asynchronously. guard let exportSession = initExportSession( composition: composition, destinationURL: destinationURL, layerComposition: layerComposition) else { delegate?.exporterDidFailExporting(exporter: self) return } // Execute the exporting exportSession.exportAsynchronously(completionHandler: { if let error = exportSession.error { print("Export error: \(error), \(error.localizedDescription)") } self.delegate?.exporterDidFinishExporting(exporter: self, with: destinationURL) }) } Not sure how to implement a custom compositor that performs the same animations as this reproducible case: class AnimationCreator: NSObject { // MARK: - Target Animations /// Creates the target animations. static func addAnimationsToTargetView(_ targetView: TargetView, startTime: Double) { // Add the appearance animation AnimationCreator.addAppearanceAnimation(on: targetView, defaultBeginTime: AVCoreAnimationBeginTimeAtZero, startTime: startTime) // Add the pulse animation. AnimationCreator.addTargetPulseAnimation(on: targetView, defaultBeginTime: AVCoreAnimationBeginTimeAtZero, startTime: startTime) } /// Adds the appearance animation to the target private static func addAppearanceAnimation(on targetView: TargetView, defaultBeginTime: Double = 0, startTime: Double = 0) { // Starts the target transparent and then turns it opaque at the specified time targetView.targetImageView.layer.opacity = 0 let appear = CABasicAnimation(keyPath: "opacity") appear.duration = .greatestFiniteMagnitude // stay on screen forever appear.fromValue = 1.0 // Opaque appear.toValue = 1.0 // Opaque appear.beginTime = defaultBeginTime + startTime targetView.targetImageView.layer.add(appear, forKey: "appear") } /// Adds a pulsing animation to the target. private static func addTargetPulseAnimation(on targetView: TargetView, defaultBeginTime: Double = 0, startTime: Double = 0) { let targetPulse = CABasicAnimation(keyPath: "transform.scale") targetPulse.fromValue = 1 // Regular size targetPulse.toValue = 1.1 // Slightly larger size targetPulse.duration = 0.4 targetPulse.beginTime = defaultBeginTime + startTime targetPulse.autoreverses = true targetPulse.repeatCount = .greatestFiniteMagnitude targetView.targetImageView.layer.add(targetPulse, forKey: "pulse_animation") } }
Posted Last updated
.
Post not yet marked as solved
0 Replies
433 Views
I have an issue with my macOS objC app that uses CATextLayer instances that adapt to the app appearance (dark, light). I had no problem with Ventura, so I suppose this is a Sonoma bug. But maybe I'm not doing the right things. Within -updateLayer , I call stringLayer.foregroundColor = NSColor.textColor.CGColor. (stringLayer is an instance of CATextLayer.) NSColor.textColor should adapt to the app appearance. But the color doesn't always change when the app appearance changes. So the text would turn black in dark mode (hence illegible) and white in light mode when I toggle the mode in the system preferences. To investigate wether the issues was specific to the system text color, I tried (again, within -updateLayer): NSColor *color = [NSApp.effectiveAppearance.name isEqualToString:NSAppearanceNameDarkAqua]? NSColor.redColor : NSColor.greenColor; stringLayer.foregroundColor = color.CGColor; I basically get the same issue. The correct color shows when the app launches, but doesn't change the first time I toggle the mode (dark/light). So the wrong color associates with the app appearance (red with light mode and green with dark mode). The code below works : NSColor *color = [NSApp.effectiveAppearance.name isEqualToString:NSAppearanceNameDarkAqua]? NSColor.redColor : NSColor.greenColor; NSDictionary *dic = @{NSFontAttributeName: [NSFont labelFontOfSize:10.0], NSForegroundColorAttributeName:color}; NSAttributedString *string = [[NSAttributedString alloc] initWithString:@"test" attributes: dic]; stringLayer.string = string; But the code below doesn't. The layer text color doesn't change when the app appearance changes. NSDictionary *dic = @{NSFontAttributeName: [NSFont labelFontOfSize:10.0], NSForegroundColorAttributeName:NSColor.textColor}; NSAttributedString *string = [[NSAttributedString alloc] initWithString:@"test" attributes: dic]; stringLayer.string = string; Note that the issue appears to be specific to the foreground color. The background color (which I update in the same method) is always set properly.
Posted
by jeanlain.
Last updated
.
Post marked as solved
6 Replies
1.3k Views
My app keeps getting crashed for the same reason in some iphone(iOS 17) and I need help. Here is the lastExceptionBacktrace. "lastExceptionBacktrace" : [ {"imageOffset":972256,"symbol":"__exceptionPreprocess","symbolLocation":164,"imageIndex":10}, {"imageOffset":179200,"symbol":"objc_exception_throw","symbolLocation":60,"imageIndex":7}, {"imageOffset":1516452,"symbol":"-[NSException initWithCoder:]","symbolLocation":0,"imageIndex":10}, {"imageOffset":195548,"symbol":"CA::Layer::set_position(CA::Vec2 const&, bool)","symbolLocation":168,"imageIndex":19}, {"imageOffset":195340,"symbol":"-[CALayer setPosition:]","symbolLocation":52,"imageIndex":19}, {"imageOffset":195204,"symbol":"-[CALayer setFrame:]","symbolLocation":396,"imageIndex":19}, {"imageOffset":409656,"symbol":"__26-[_UILabelLayer setFrame:]_block_invoke","symbolLocation":56,"imageIndex":12}, {"imageOffset":409388,"symbol":"-[_UILabelLayer _setFrameOrBounds:settingAction:]","symbolLocation":60,"imageIndex":12}, {"imageOffset":426392,"symbol":"-[_UILabelLayer setFrame:]","symbolLocation":104,"imageIndex":12}, {"imageOffset":104744,"symbol":"-[UIView _backing_setFrame:]","symbolLocation":240,"imageIndex":12}, {"imageOffset":97808,"symbol":"-[UIView(Geometry) setFrame:]","symbolLocation":296,"imageIndex":12}, {"imageOffset":106944,"symbol":"-[UILabel setFrame:]","symbolLocation":112,"imageIndex":12}, {"imageOffset":16705216,"symbol":"-[UITableViewHeaderFooterView layoutSubviews]","symbolLocation":220,"imageIndex":12}, {"imageOffset":209368,"symbol":"-[UIView(CALayerDelegate) layoutSublayersOfLayer:]","symbolLocation":1528,"imageIndex":12}, {"imageOffset":424072,"symbol":"CA::Layer::layout_if_needed(CA::Transaction*)","symbolLocation":500,"imageIndex":19}, {"imageOffset":221860,"symbol":"-[UIView(Hierarchy) layoutBelowIfNeeded]","symbolLocation":308,"imageIndex":12}, {"imageOffset":16700796,"symbol":"-[UITableViewHeaderFooterView _sizeThatFits:stripPaddingForAbuttingView:isTopHeader:]","symbolLocation":192,"imageIndex":12}, {"imageOffset":16733416,"symbol":"-[UISectionRowData _headerFooterSizeForSection:inTable:withTitle:detailText:isHeader:stripPaddingForAbuttingView:isTopHeader:]","symbolLocation":680,"imageIndex":12}, {"imageOffset":2595124,"symbol":"-[UISectionRowData refreshWithSection:tableView:tableViewRowData:]","symbolLocation":464,"imageIndex":12}, {"imageOffset":2604748,"symbol":"-[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:]","symbolLocation":104,"imageIndex":12}, {"imageOffset":2604572,"symbol":"-[UITableViewRowData heightForTable]","symbolLocation":52,"imageIndex":12}, {"imageOffset":2599644,"symbol":"-[UITableView _updateContentSizeSkippingContentOffsetAdjustment:]","symbolLocation":168,"imageIndex":12}, {"imageOffset":16599748,"symbol":"-[UITableView _rebuildGeometryForcingRowDataUpdate:skipContentOffsetAdjustment:updateImmediatelyIfPossible:]","symbolLocation":140,"imageIndex":12}, {"imageOffset":16595412,"symbol":"-[UITableView setLayoutMargins:]","symbolLocation":204,"imageIndex":12}, {"imageOffset":16595180,"symbol":"-[UITableView _setDefaultLayoutMargins:]","symbolLocation":52,"imageIndex":12}, {"imageOffset":16595032,"symbol":"-[UITableView didMoveToWindow]","symbolLocation":288,"imageIndex":12}, {"imageOffset":74184,"symbol":"-[UIView(Internal) _didMoveFromWindow:toWindow:]","symbolLocation":1716,"imageIndex":12}, {"imageOffset":1969584,"symbol":"-[UIScrollView _didMoveFromWindow:toWindow:]","symbolLocation":88,"imageIndex":12}, {"imageOffset":73152,"symbol":"-[UIView(Internal) _didMoveFromWindow:toWindow:]","symbolLocation":684,"imageIndex":12}, {"imageOffset":71756,"symbol":"__45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke","symbolLocation":124,"imageIndex":12}, {"imageOffset":71520,"symbol":"-[UIView _postMovedFromSuperview:]","symbolLocation":484,"imageIndex":12}, {"imageOffset":66468,"symbol":"-[UIView(Internal) _addSubview:positioned:relativeTo:]","symbolLocation":2180,"imageIndex":12}, {"imageOffset":555240,"symbol":"-[UIWindow addRootViewControllerViewIfPossible]","symbolLocation":728,"imageIndex":12}, {"imageOffset":1651088,"symbol":"-[UIWindow setRootViewController:]","symbolLocation":364,"imageIndex":12}, {"imageOffset":27056,"imageIndex":2}, {"imageOffset":26016,"imageIndex":2}, {"imageOffset":2179544,"symbol":"-[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:]","symbolLocation":320,"imageIndex":12}, ...... {"imageOffset":2433472,"symbol":"-[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:]","symbolLocation":288,"imageIndex":12}, {"imageOffset":60072,"symbol":"-[FBSScene _callOutQueue_didCreateWithTransitionContext:completion:]","symbolLocation":324,"imageIndex":9}, {"imageOffset":59716,"symbol":"__92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke.108","symbolLocation":280,"imageIndex":9}, {"imageOffset":54696,"symbol":"-[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:]","symbolLocation":168,"imageIndex":9}, {"imageOffset":103264,"symbol":"__92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke","symbolLocation":352,"imageIndex":9}, {"imageOffset":17152,"symbol":"_dispatch_client_callout","symbolLocation":20,"imageIndex":8}, {"imageOffset":32072,"symbol":"_dispatch_block_invoke_direct","symbolLocation":284,"imageIndex":8}, {"imageOffset":39404,"symbol":"FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK","symbolLocation":52,"imageIndex":9}, {"imageOffset":39276,"symbol":"-[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible]","symbolLocation":240,"imageIndex":9}, {"imageOffset":38980,"symbol":"-[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource]","symbolLocation":28,"imageIndex":9}, {"imageOffset":228044,"symbol":"CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION","symbolLocation":28,"imageIndex":10}, {"imageOffset":224584,"symbol":"__CFRunLoopDoSource0","symbolLocation":176,"imageIndex":10}, {"imageOffset":218460,"symbol":"__CFRunLoopDoSources0","symbolLocation":340,"imageIndex":10}, {"imageOffset":213560,"symbol":"__CFRunLoopRun","symbolLocation":828,"imageIndex":10}, {"imageOffset":212504,"symbol":"CFRunLoopRunSpecific","symbolLocation":608,"imageIndex":10}, {"imageOffset":13804,"symbol":"GSEventRunModal","symbolLocation":164,"imageIndex":11}, {"imageOffset":2290512,"symbol":"-[UIApplication _run]","symbolLocation":888,"imageIndex":12}, {"imageOffset":2288012,"symbol":"UIApplicationMain","symbolLocation":340,"imageIndex":12}, {"imageOffset":24608,"imageIndex":2}, {"imageOffset":23876,"symbol":"start","symbolLocation":2104,"imageIndex":13} ],
Posted Last updated
.
Post not yet marked as solved
0 Replies
541 Views
I’m trying to achieve vertical split view in SwiftUI. There are two views, top one is Map (MKMapView actually, wrapped with UIViewRepresentable) and bottom one for this example could be Color.red. Between them there’s a handle to resize the proportions. Initial proportions are 0.3 of height for bottom, 0.7 for map. When resizing map frame, it feels choppy and slow. Replacing MapView with any other view does not produce the same issue. Issue appears only on my real device (iPhone 11 Pro Max) simulator works fine.
Posted
by dvxiel.
Last updated
.