Bi-directional NSLevelIndicator (origin at center of indicator) - how? - objective-c

I need a graphical indication of signed "wrongness" of something, i.e. 0 is perfect, -1.0 is completely wrong in one direction, 0.3 is partly correct, but skewed to the right, 1.0 is completely wrong in the other direction. Sort of like a volt-meter.
I've searched and searched and the closest I've found was this thread: Bi-directional level indicator, but that seems to have ended abruptly, and the solution proposed doesn't seem to fit the poster's (or my) requirements.
I can't draw, but I've tried doing some crude mock-ups in IB to illustrate what I mean. The outer regions would be colored differently and there'd probably be axis information and other stuff in a final implementation. (Apparantly I'm not allowed to post images. I'll try ascii art instead)
Spot on:
[....|....]
Completely wrong to the left:
[|||||....]
Completely wrong to the right:
[....|||||]
Partly wrong:
[....|||..]
Now, I suppose I have a few options:
Subclass NSLevelIndicator (or NSLevelIndicatorCell) I don't mind this, but I'm not quite sure how to do it. From searching the web I've found answers to questions such as changing style (rounded corners, fx) and reverse of critical coloring, but such solutions seem to imply a complete override of the drawing functions, which means you lose whatever NSLevelIndicator(Cell) is doing for you with the gradients and all. I had hoped it was possible to manipulate various variables and stay clear of the actual drawing.
Create a custom view I'm not graphically minded in any way, but I suppose a start would be Apples custom view guide: Subclassing NSView. I'd like to use standard UI components as much as possible, as I'm sure Apple has better UI designers than me. I've done a custom 2D graph view earlier, which I think is OK, but that is really more of a custom view in my opinion.
Borrow someone else's implementation (or look through for inspiration) I have searched but haven't found anything, which is odd as I would assume this would be a common setup. It doesn't have to resemble the NSLevelIndicator as such. It could be a volt-meter or similar.
So which approach do I take? If 1 or 3 I need some guiding. If 2 I would like to know if the Apple documentation is sufficient for a novice like myself, or if I need further information.
PS: Asking multiple questions in the same post is probably not wise, but consider it a bonus question. When subclassing NS* stuff, how do you know which methods to override? Apple's class reference only lists public methods as far as I can tell. What I do is create a subclass and then type "self." and see what appears, but that's not very easy to sort through.

It is strange, maybe this is a recent apple update. But now NSLevelIndicator supports negative values as minimum.
So one just need to set minimum value to -n and maximum to n. The 0 will be at the middle.

Related

Reasons not to create an outlet by connecting directly between code and storyboard?

I am following the fantastic Matt Neuburg iOS7 Programming Fundamentals book and have just gone through the section discussing various ways to create an outlet.
The very last one he explains is connecting directly between code and the storyboard (nib editor). All of the ones before that involve HUD popovers, engaging with the connections inspector directly and so on, and are generally more involved, having more steps to follow before an outlet is created.
I'm still not sure on why you would use one of these more involved ways to create an outlet? Is it safe to infer that they are more reliable in terms of knowing that the outlet is properly set up? And if so, how exactly do these other ways achieve this?
The reason I'm asking is that I'd like to get on top of one way of creating outlets and if the hard way is the best way I'd rather get used to it right from the off.
They are pretty much equivalent, and it's a good idea to know about all of them, because a lot depends on where you are working and what you are seeing when you start. (For example, you can draw from the destination to the source or from the source to the destination.)
The problem with the one that makes your code for you (using an assistant pane so that you are seeing the storyboard and the code simultaneously) is:
It takes a lot of space; it's not a very good approach on my small-screen 13-inch MacBook Pro, for example, because there really isn't room for that split pane arrangement.
You have to get out of the split pane arrangement later, so why get into it in the first place?
Most important: it works only in a limited range of situations. It works if what you're connecting to is the superview's view controller, but it doesn't work at all if you're connecting between one view and another.
So my advice remains, as implied by the book: be fluid in all ways of making / exploring outlets and actions! The more you know, the more comfortable and secure you'll be.

Framework of choice for building smart histogram in cocoa touch

I'm familiar with the basics of objective-c and cocoa touch and I want to start now my first large iOS project.
I want to build an iPad app with a histogram like you know it from several photo apps where you can see e.g. the distribution of brightness in a picture. But it needs to be smart, i.e. scrolling horizontal, setting borders and pinching for zoom-in and zoom-out.
Is it possible to handle this requirements with iOS7 standard API or do I need a 3rd party framework like Core-Plot to achieve a histogram I described, and if so, which one would you prefer and why.
Thanks for your help!
Is it possible to handle this requirements with iOS7 standard API or do I need a 3rd party framework
It's certainly possible to do it all yourself with no help from anybody except the frameworks that Apple provides. Whether that's the best solution for you, only you can decide. I think these are the relevant considerations:
You seem to have some fairly specific requirements and it sounds like you may need fairly fine control over exactly how this histogram looks and works. These are good reasons to create the histogram yourself.
You're still fairly new to Objective-C, Cocoa Touch, etc. That's a good reason to look for something that's already written. You'll save a lot of time and frustration, but you may have to be a little more flexible in terms of what you're willing to accept; it's unlikely that anybody has already written exactly the thing you want.
I'd suggest taking a shot a building what you want, and if it turns out to be a bigger thing than you're ready to tackle, you'll at least have a better understanding of what's involved.
To get started, read up on UIBezierPath. All you really need to do is to create a view that accepts an array of numbers and draws the corresponding graph. Don't worry about zooming and scrolling yet, just make a view that draws the graph. Once you have that, you can read up on UIScrollView, which will give you the scrolling and zooming with almost no work.

cocos2d choose the right pattern

I'm working on a game with finding objects on the screen which has also implemented the parallax effect.
For certain reasons I've added my objects as CCMenuItems to the parallax layers
I'd like to know which will be the best design pattern suitable to me in order to handle my objects;
I've found that are six (maybe more of this but this is what I've found so far)
Model-View-Controller
Delegation
Target action
Notifications
Block model
Managed memory model
Any tutorial for the best one would be great! ;)
My answer: None of these at this time.
Because a) your question is too broad and not specific enough. and b) this indicates you need more general knowledge about patterns first to be able to use them meaningful. I think if you had this knowledge already you would have put the question differently.
I suggest you read up on patterns and software design more, first.
Book Tip: Head First Design Patterns by O'Reilly.
http://www.amazon.com/First-Design-Patterns-Elisabeth-Freeman/dp/0596007124/ref=sr_1_1?ie=UTF8&qid=1328729374&sr=8-1

Create swipe controlled simple flipbook style animation in ObjC

I am a beginner in Obj C development, though quite experienced (over 10 years) with other ECMAscript based languages and OOP development.
I want to build a simple flipbook style animation, controlled through swiping motion. I'm sure extremely simple for any advanced ObjC coders.
Can anyone with extensive ObjC-CocoaTouch experience give me some higher level recommendations?
ie,
1 -general application design, should I start with a simple view based application, or navigation based or?
2 -should I use 3rd party animation frameworks such as Cocos2D, or stick with built in classes and methods?
3 -if using built in methods, classes, what is the recommended way of achieving a animation, that will be controlled via swipe and touch gestures?
4 -I want to eventually have multiple 'flipbooks' that I can 'instantly' swap with one another, ie to give the net effect of an object changing color, etc, but not sure how to approach this from a memory management point of view, related to #1 above
Except for point 3 above, I'm not expecting any actual code examples. Just general guidelines to follow and perhaps, what are some next steps I should take in my goal as an ObjC code samurai.
While I am no expert I can think of a few things you could pursue to get the effect you want. Sounds like you want have a somewhat immersive experience for users. Cocos2D would definitely fit that bill. Me and my team at Get Set Games have been using it for the past year and have not been dissapointed with it. We haven't done the flipbook effect you speak of but quite possibly someone in the Cocos2D forums has implemented are at least attempted this. Forums are accessible here.
Having said that I think starting with the iPhone SDK UIKit framework and basic examples that come with it are great. There is a great array of samples on scrolling, swiping, etc. If you want to hook in Cocos2D or other frameworks later that's definitely an option.

Where can I get better Apple documentation?

More often than I'd have hoped I seem to come across method/property definitions in Apple's documentation that are vague at best and meaningless, to me, at worst. For example, take the following method description from NSNumberFormatter Class Reference:
setPartialStringValidationEnabled:
Sets whether partial string validation
is enabled for the receiver.
- (void)setPartialStringValidationEnabled:(BOOL)b
Parameters
b YES if partial string validation is enabled, otherwise NO.
So, let's just assume that the shoddy educational system I went through and any previous projects I've worked on didn't cover "partial string validation" in Cocoa and I would like to dig into it some more to see what this property is all about. Where does one look (aside from Google)? I hate to pester forums for something I should be able to look up easily myself.
I have come across situations like this enough times now that I think I may be approaching Apple's docs incorrectly. Any suggestions? Tips/tricks? 3rd party resources?
Partial string validation is explained in NSFormatter class.
Setter methods like that are sometimes explained in more detail in the getter method, the introduction text in class documentation, or one of the documentation companion guides you see linked on the bottom left. Sometimes you can also find clues in the Cocoa headers, by right-clicking on the name when you're writing code and selecting 'jump to definition'.
Otherwise, there's really no other resource other than google, asking about it on sites like this or using a mailing list. You could always write some code to test what happens when you change its value. And of course, if it's something really confusing it's good too to take the time to file a radar bug report so it will hopefully be improved in the future.