Disabling implicit animation?

I’ve spent hours designing and building my app’s UI, and now I’ve hit a snag: I can’t disable iOS’s implicit animations, which creates a glitchy look when updating the UI in code.

Here, I’m synchronizing my view to the model just before I open my editor view. Programmatically setting the segment control’s index causes an implicit animation:


On iOS (Obj-C, Swift), I’d be able to set the value without animation, either by using a UIView animation block, a setter method that offered and “animated” parameter, or a CATransaction block, like so:

	[CATransaction begin];
	[CATransaction setAnimationDuration:0.0];

	// Update UI control values here

	[CATransaction commit];

I’ve tried the same code in XOJO, but it doesn’t work in my case. (Some functions here are using third-party iOS libraries.)

Dim CATransaction As ptr = NSClassFromString("CATransaction")

Declare Sub CATransaction_begin Lib UIKitLib Selector "begin" (id As ptr)
Declare Sub CATransaction_setAnimationDuration Lib UIKitLib Selector "setAnimationDuration:" (id As ptr, duration As Double)
Declare Sub CATransaction_commit Lib UIKitLib Selector "commit" (id As ptr)

CATransaction_setAnimationDuration(CATransaction, 0.0)

// Set my UI control values
Me.PTTS_BorderWidth.TRMSS.SnapValue = Integer(PTGlobals.BorderWidthPreset)
Me.SB_BorderColor.SelectedSegmentIndex = Integer(PTGlobals.BorderColorPreset)


Various other tricks, such as hiding the control, setting it, and showing it, didn’t work. I really don’t want to set up a UIView animation block because it’s going to be tedious to implement everywhere I’m updating the UI.

Perhaps I’m missing something simply?

Have you tried setting the segmented control’s value with a declare?

1 Like

Oh, great idea; I’ll try that. :+1:

Setting the UISegmentedControl’s value with a declare didn’t work, but it’s an iOS-thing. Found some posts on the internet where others were having the same problem in Swift. The solution was to use a declare to [UIView performWithoutAnimation:] and have it point to address of a method that updates the index (using XOJO’s API) and then writing another declare to call the UIKit method layoutIfNeeded on the segmented control. Lot’s of hoops, but it gets the job done.

Side question for anyone reading: Is it possible to declare methods inline, like you can in Obj-C or Swift with blocks? Ideally, it would be great to provide my block code to a declare without adding another method to my class.


1 Like