UISlider or UISwitch with a stationary mask? - cocoa-touch

I've found a gorgeous switch that I'd like to implement in iOS. The artist (#jasonlong) has kindly shared his PSD of the components at 365psd.com, along with a crafty little javascript as a demo.
Now, here's where I get into trouble... The custom UISlider and UISwitch examples I've found seem to rely on a track that's stationary with a movable knob/toggle. In the switch below, it would require a knob/track to animate behind a mask that also passes through touch events.
I've never been much of an interface coder, but this cute little bugger is just to awesome to leave alone. Can someone point me in the right direction?

I suggest just having the background stationary, and just fade between them? Sliding the track is probably not going to work so well, as you can still see the green/white around the edge of the knob.

Related

How to acheive animation effects like(word puzzle game) in iphone application?

i need to achieve an animation effect like (the Effects in "Pic Something","Pic Reveal" and so on) in my app.
What i am saying is i need to implement this tasks
Task1: when the user touches one Letter, then it change its frame(current position) to another frame(target position).
Task2:when the user touch the Letter(in Target position), it comes back to its original position again.
this can be clearly understood if u see the sample Apps.
I didn't find out any samples on internet also.
Thanks in Advance..
Take a look at UIView animation and animation blocks in iOS, that's what you need. With them you can create any animation you like. Here's a nice tutorial.
And about the whole system you described - I would create an NSDictionary of UIView positions and attach those to the corresponding tags of UIViews- this way you will always know from which place every UIView came from.

Infinite UIScrollView

I would like to implement a timeline, much like one you can find in iMovie or Final Cut, which you can scroll in either direction. Scrolling to the left would go back in time ( months ) and scrolling to the right would go forward in time, creating a smooth continues path.
What would be the best way to implement this?
Do tricky things with UIScrollView
Subclass UIView and try to re-create inertial scrolling
A disadvantage of recreating the inertial scrolling is if Apple ever decides to change it that my app will feel weird. I personally do not like it when an app does not feel system integrated, this includes games like tower madness where they made their own scrollview which works really bad and feels wrong.
Apple has and example project featuring infinite scrolling it's called StreetScroller, the description says:
Demonstrates how a UIScrollView subclass can scroll infinitely in the
horizontal direction.
I hope this helps you.
StreetScroller can only support no paging mode. I wrote a class based on the StreetScroller and support paging & no paging at the same time.
https://github.com/hellohalo/InfiniteScrollView

Scaled preview: use NSTextView, NSTextField, CATextLayer, or drawInRect?

I'm programming a cocoa app that presents text (vertically and horizontally) centered on a projector screen.
I'd like to have a small preview of what I see on the "wall" in a cocoa window on the computer's screen (in a NSCollectionView). Just like "presenter mode" in Powerpoint where you see the current and the next slide as previews.
Which way do you recommend for implementing the presented text?
NSTextField turned out to be tricky for aligning and scaling the text. CATextLayer, on the other hand, feels a little bit overkill for such a simple task, even though the scaling works like a charm. Would using NSTextView or drawInRect be a good trade-off?
I appreciate your assistance in making sure that I didn't miss something out before I spend hours and days on this :) My goals are to keep it robust and simple. Thanks!
CATextLayer is definitely not overkill. In fact, a CATextLayer is considerably more lightweight than an NSView and would seem ideal for your situation.

How should I design displaying a dynamic map? (Coordinates + Lines)

So I want to have a view (NSView, NSOpenGLView, something CG related?) which basically displays a map. Such as:
http://dump.tanaris4.com/map.png
Obviously that looks horrible, but I did it using an NSView, and it draws SO slow. Clearly not designed for this.
I just need to allow users to click on the individual (x,y) coordinates to make changes, and zoom into a certain area (to see it better).
Should I go the OpenGL route? And if so - any suggestions as to how to get started? (I was able to follow the guide to draw a triangle, so that's good).
I did find this post on zooming in an NSView: How to implement zoom/scale in a Cocoa AppKit-application
My concern is if I'm drawing over 6000 coordinates and the lines connecting them, this isn't efficient at all.
I don't think using OpenGL would be of any good here. The problem does not seem to be the actual painting, but rather the rendering strategy. You would need a scene graph of some kind to dynamically handle level of detail and culling.
Qt has all this packaged in a nice class class QGraphicsScene (see http://doc.qt.nokia.com/latest/qgraphicsscene.html for reference, and http://doc.qt.nokia.com/main-snapshot/demos-chip.html for an example).
Some basic concepts you should consider using:
http://en.wikipedia.org/wiki/Scene_graph
http://en.wikipedia.org/wiki/Quadtree
http://en.wikipedia.org/wiki/Level_of_detail
Try using core graphics for this, really there is so much that could be done. Watch the video Practical Drawing for iOS Developers from WWDC 2011 and it should give an over view of what can be done with CG.
I believe even CoreGraphics will suffice for what you want to achieve, and that should work under a UIView if you draw the rectangle of your view completely under the DrawRect method of your UIView (you must overload this method). Please see the UIView Class Reference. I have a mobile application that logs points on the UIMapKit, kind of like Nike+, and it certainly works well for massive amounts of points/line segments. There is no reason why this simple approach cannot work for you as well.

Programmatically resizing NSSplitView

I used to use and love RBSplitView, however I failed at reimplementing it programmatically as a certain version of xcode does not support IB plugins anymore.
Therefore I went back to using NSSplitView. NSSplitView is fine for what I need, the thing is that the autoSave of NSSplitView is broken. So I decided to implement it myself.
The thing I am doing at the moment is resizing 1 of the subviews of the NSSplitView.
What is the proper way of resizing an NSSplitView? - setPositionOfDivider:itIndex: should be the way to go ( haven't tried it ), however I do not know how to get the current position of the divider.
-- thanks in advance
In my experience, NSSplitView hates you and wishes you harm. RBSplitView is so much better, it is worth IMO the headache of programatic layout (and I've been so burned with the ShortcutRecorder IB plugins that I will never go back to IB plugins).
That said....
The only way that I know of to determine the current position of the divider is to look at the subviews, find the divider's view, take it's frame, and work out its position keeping in mind the dividerThickness. It is insane that you have to write that code, but the code isn't that incredibly difficult, and you can put it in a category.
Or go back to RBSplitView while you still can, if your needs are ever going to be complicated.
I'm using Swift here but the same method should exist in Objective C:
mySplitter.setPosition(123, ofDividerAtIndex: 0)