Posts

Post not yet marked as solved
0 Replies
221 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 marked as solved
2 Replies
248 Views
I'm working on a demonstration iOS project with no code other than the default templates that Xcode provided. I'm using the latest Xcode v15.3. In storyboard I've added 2 views to the default View Controller to which I've added constraints such that by default, the first one takes up the top half of the screen and the second one roughly the remainder (bottom half of the screen). Then I've added additional constraints for a "landscape" view, i.e. using the width=regular, height=compact such that the first view takes up the left half of the screen and the second view roughly the remaining right side. In the property inspector I've toggled the "Installed" checkboxes so that the correct constraints are applied for each size class. Both portrait and landscape views look correct in the storyboard editor, and Xcode reports no warnings. But when I run Simulator and rotate left to landscape mode, it's not applying the wR:hC size class, and I get a "wide" format as if I hadn't added any additional constraints at all. Is there some reason why Simulator isn't applying the correct constraints when the device gets rotated? Is this an Xcode bug or did I do something wrong? I've attached a few screen grabs from storyboard and the simulator. You can see which constraints are which based on the icon color in storyboard's document outline pane.
Posted
by tgherzog.
Last updated
.