0

I'm building a cross platform UI library's iOS implementation using UIKit, one of the library's primary function is allow user to change the child control's size freely, and the parent control's size will automatically adapt.

Since refresh the parent's size everytime when a child's size changed is inefficient and unnecessery, so I designed the UI system to refresh all "dirty" control's position, size, and a lot of things before actual device draw/render happen. On iOS, I use CADisplayLink to call the refresh method, then I discovered the event was called AFTER everything has presented onto screen, that caused the following problem:

  1. User will see a "crashed" layout first. (The render happens first)
  2. After a short period (CADisplayLink's event triggered), everything will return to normal.

At first I thought my way of using CADisplayLink is wrong, but the solution cannot be found anywhere, so I'm quite despaired right now (I'm going to hang my self!!)

Or maybe I shouldn't use CADisplayLink at all?

Please Help me!


PS. Since I'm building a cross platform thing I'm actually using MonoTouch, but I believe the basic concept is same.

PS2. And since I'm using MonoTouch, which is C#, so the description above may not fit in the Objective-C world (like the word "event", I think the Obj-C relevant is selector, or something ^_^)

PS3. Also please pardon my poor English, feel free to ask me any questions if my description isn't clear enough.

Codes here:

CADisplayLink _displayLink = CADisplayLink.Create(Update);  //Update is my refresh method
_displayLink.AddToRunLoop(NSRunLoop.Current, NSRunLoop.NSDefaultRunLoopMode);

Should be easy enough to understand ^_^

horeaper
  • 361
  • 1
  • 16
  • Can you invoke your first refresh before the first callback from `CADisplayLink` occurs? Can you post more of your code? It is hard to see how your controls are setup and how `CADisplayLink` interacts with them. – jonathanpeppers Jan 17 '13 at 13:09
  • The control setup code are too complex to post here, but I can give you a rough idea: my control is a wrapper of UIControl, each control store it's position/size/visibility data inside a buffer, rather than apply them to UIControl immediately. Those datas are applied in the Update() method, which used to create the CADisplayLink as the code above shows. – horeaper Jan 18 '13 at 07:14
  • Since the controls position/size/visibility can change by time, I need to make sure the Update() was called before UIControl get rendered onto screen, here is the problem! – horeaper Jan 18 '13 at 07:15

1 Answers1

0

From all the information of what I can gather, is that basiclly there is no way of doing that. So I have modified my layout code, which now apply the properties immediatly after a value is set. Some optimization still required, but no need to rely on CADisplayLink anymore.

Thanks anyway!

horeaper
  • 361
  • 1
  • 16