How to animate NSAttributedString? - ios

I need to animate the color and scale of an attributed string. CATextLayer does not work for me, because it can only change the foreground color for plain strings..
I found another solution, but I did not get it to work either Link
I need to get it to work on both Mac and iOS.
I think layers would be ideal, because I can do the scaling there easily..
Do you have any ideas?

If you need to animate a property that is not animatable, you can use CADisplayLink. That allows you to create your own animation by executing a method every time the screen refreshes. Although it looks sort of low-level, it is not really difficult to implement it.
You can find tutorials/examples on the web easily.
Note: It does not trigger your method periodically, therefore do not assume anything about timing and keep a counter and calculate progress your animation by yourself. Apart from that, CADisplayLink is cool.
Edit: As Max pointed out, CADisplayLink is not available for Mac. But there is CVDisplayLink, I guess you can achieve the desired animation by that. For more info on CVDisplayLink, you can have a look at that answer by Brad Larson.

Related

Is there a way to overlay frames in SpriteKit?

As the title states, is there a way to stop the canvas / SKScene from clearing the contents of the current frame, and just draw over the current frame? Now the contents of the scene/frame are cleared every update cycle, i would like to just draw over the previous frame.
I have worked with OpenFrameworks and other visual programming frameworks, and the way it worked there was; you draw stuff on the update call, on the next update call you set a background again to 'clear' the previous frame.
I have looked through the whole documentation of SpriteKit and couldn't find anything. I also tried to emulate the effect by pushing more nodes onto the scene, having them follow one step behind the 'new' nodes. This was, as i expected, way to heavy on CPU / RAM.
No code, i know, i'm sorry, but the stuff i use is pretty basic. Any one of you have any thoughts on this?
Hope to hear from you, thanks.
You should be able to do this by setting the clearsContextBeforeDrawing property on your SKView to NO.
clearsContextBeforeDrawing is a property of UIView, which SKView is a subclass of.
I wouldn't consider this to technically be Sprite Kit providing the behavior, but I believe it's what you're looking for.
Note: I didn't actually test this, so it's possibly that this won't actually work. It would theoretically work perfectly for UIKit.

Detect UI changes

I have a function that continuously takes screenshots of an UI element to then draw it itself. The UI element can change, so I take a screenshot in very short intervals to not have the second drawing lag behind (please don't question this and just assume that redrawing it is the right way. The use case is a bit more complicated).
However, taking the screenshot and invalidating the previous drawing to redraw it is quite an expensive operation, and most often not needed as the UI element doesn't update that often. Is there a way to detect when a UI element changes in such a way that it needs redrawing, including when it happens to one of its subviews? One solution would be to copy the state and the states of all its descendents and then check that, but that doesn't seem like a good solution either. iOS must know internally when it needs to redraw/update the views, is there any way to hook into this? Note that I tagged this UIKit and Core-Animation, I suppose the way to go for this is Core-Animation, but I'm open for a solution that uses either of these.

Build a "grouping" animation like Apple's iPad mail app

How can I do this "grouping" animation like Apple mail or the Gmail iPad app?
Does this need to be hard coded, and completely done with the animation framework, or does Apple expose an API for this to be done. I checked the developer docs, and I don't see anything like this. But Gmail was able to exactly replicate Apple's animation, and that's why I am curious to know if it can be done in an easier way.
I am 95% sure Apple does not have a UIStackOfPaperViewController or anything like that. You would have to code this up yourself.
Conceptually, it isn't too complicated: a background view with a texture, and each subview tilted at a random angle and a drop shadow beneath. You could do the drop shadow by drawing a gradient in a view around the "real" view. Core Animation's default behaviors would probably do the right thing, e.g. if you create the page view off screen and then set the final location, it will fly onto the stack pretty much how you would like it.
If you don't need support for releases earlier than iOS 6, there's probably good stuff in the Collection View Controller to make this easier.
Hopefully that's enough information to get you started, but your question is really broad. It's difficult to answer "How do I do X?" if you don't specify your starting point, or answer "How can I do this in an easier way?" if you don't specify what you think the hard way is first.

iOS: How to make the CADisplayLink's event called BEFORE actual screen draw?

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:
User will see a "crashed" layout first. (The render happens first)
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 ^_^
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!

How to make a flowing ribbon background for iOS like the one on PS3?

I've started playing with animated background views in iOS, and I really think it improves the presentation of my app. However, I'd like to create a background that I don't know how to make. The effect I'm looking for is something like this:
activeden.net/item/green-ribbon-animated-banner-background/49229
http://i156.photobucket.com/albums/t34/pspelver/wallpaper.jpg
I'm not sure how to actually design the graphic for this kind of pattern, or if there is even a better way to do it with core graphics. Can anyone please advise? Thanks.
Try to find (or create yourself) an animated image of what you want. You could probably just find or make a video of the effect you want and do a frame-by-frame change into something like a .gif. Then set that as your background. The problem I see with the effect you want is that it will probably take a lot of system resources.

Resources