iPhone Deck Game interface - iphone

I wrote the code of a card game .. but now it's time todo the graphic and Interface
What's the best approach to represent a card ??
a) CALayer
b) UIView
c) UIButton
Which one is best to animate and receive user touches???
What do you recommend??
Thanks in advance

GeekGameBoard is older Apple-provided example code for card and board games that implements the UI in CALayers. Another user modified it to run on the iPhone so it might be helpful code for you to look at. The modified project is on bitbucket.

as UIButton is subclass of UIView, there's no so much difference in both of them.
If you need only 'clicks' handling, you can choose button, if you will need to override touchesBegan/touchesMoved you should override UIView instead UIButton.

A UIView subclass would probably be your best choice. You can easily receive touch events from the user, and UIView allows you to do simple animations easily.

Related

How to show a NSObject as a UIView?

I read on StackOverflow that to create a messaging speech bubble, the TTSpeechBubbleShape class is highly recommended.
Speech Bubble in iOS SDK using Objective-C
However, this class is derived from a custom NSObject class, so I have no idea how to turn this NSObject and add it into one of the cells of my custom UITableView class?
So, how does one turn a NSObject into a UIView? (Or at least show a NSObject as part of a UIView)
Thanks from a first time iOS app developer.
More info on the class:
http://api.three20.info/interface_t_t_speech_bubble_shape.php
https://github.com/facebook/three20/blob/master/src/Three20Style/Headers/TTSpeechBubbleShape.h
https://github.com/facebook/three20/blob/master/src/Three20Style/Sources/TTSpeechBubbleShape.m
Those bubble classes just prepare a path. A path can be drawn in a CGContext. You cannot draw a UIObject in any way. Learn the basics of cocoa touch... read the documentation.
A more easy way for your bubbles is a single resizable image like in this answer: https://stackoverflow.com/a/11196243/407488

showing touches on iOS device like in the simulator

For the purposes of making app demos and presentations, I would like to draw circles corresponding to touches, just like in the iOS simulator, but on the device itself.
Ideally, this would be orthogonal to other code. Perhaps a UIView which draws the circles and forwards the events, but event forwarding seems to require the other views be aware:
http://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/MultitouchEvents/MultitouchEvents.html#//apple_ref/doc/uid/TP40009541-CH3-SW17
Is there a clean way of doing this?
(I can't use the simulator for demos because my app uses gestures, MIDI, and OpenGL)
thanks!
There is a framework call fingertips which is available through cocoapods.
http://cocoapods.org/?q=on%3Aios%20fingertips
This will do what you are asking.
I don't think there's a clean way of doing this. However, this is what I would try:
Use method swizzling to hook up to all your views by swizzling the methods
- touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
for the UIView class. In addition, you may also need to swizzle some methods of UIGestureRecognizer subclasses, since they may prevent the methods listed above from being called. This way you can do your own thing (e.g. draw the touch points on the screen), and also let the views handle the touches as before.

CCSprite + NSCoding

I have subclassed NSCoding and added my game specific stuff to it such as health etc. I have serialised the object I have subclassed however upon decoding and then adding the sprite to the screen via [self addChild:sprite], it fails to draw the sprite to the screen.
I am guessing this is because CCSprite needs to also implement the NSCoding protocol so my questions are:
1) Am I right about my assumption above (I don't want to waste time implementing this solution to only find out this is not the issue)
2) What is the best way to get CCSprite to implement NSCoding? Is it to use Categories or just subclass it and force the subclass to implement the NSCoding protocol?
LOL sorry it was late at night when i wrote that, i figured out the solution by early morning. The problem i had was i was sending a subclass of CSSprite from one process to another, i was confused as to why the sprite was not being displayed in the receiving process. I figured out not all of the sprite data was being serialised. The solution i implemented was to only send across information i needed such as coordinates,image name etc and just rebuild the sprite from scratch on the receiving end :)

A view that is moving

I've no experience in making something move in my app. And I observed this effect in Flickit Pro. The Tap for details view will shake for one or two second and then stop. It looks cute and very user-friendly.
So how can I make effects like this? A gif that is moving? Or some other methods with the help of Cocoa Touch?
Thanks in advance.
Di
A high-level way would be [UIView beginAnimations: context:] (where both parameters can be NULL in this simple case). Then you can just change the properties that want to change of the view that should be animated, add some other "effects" like ease-in/out, etc. pp. When you are done with this, you just call [UIView commitAnimations] and it will animate everything for you.
However, in the case that you need more freedom, look into the CAAnimation class (its inside the QuartzCore framework).
Also: Look into the documentation for both ways (UIView / CAAnimation) and look into session 424 and 425 of the 2010 WWDC.
There are already some answers on stackoverflow on this:
Shake visual effect on iPhone (NOT shaking the device)
UIView shake animation
how to create iphone's wobbling icon effect?
and here is a link that does it on mac:
http://www.cimgf.com/2008/02/27/core-animation-tutorial-window-shake-effect/
I hope these are enough links to help.

Possible to use iPhoneSimulators framework in a Cocoa App?

I am toying with the idea of creating a iPhone UI editor that isn't Interface Builder! Mostly to see if it is possible to do... I have been able to link to the UIKit.framework in a Cocoa app that I have created by dynamically loading it (via NSBundle functionality). I have been able to instantiate an UIView from there. Now the question is... how do I get to whatever the UIView renders?
I am trying to figure out how Apple implemented their Simulator since it seems likely that they are using the frameworks under the iPhoneSimulator.platform folder to do the rendering and then displaying that in a Cocoa window...
I am not sure how far I can go with this idea..but if anyone has any ideas how to direct the output of the UIVIew to a bitmap then I could take that and display in my Cocoa window...
Thanks,
Peter
You might try making an NSView subclass that hosts a UIWindow. In the NSView's drawRect:, apply any necessary transformations, then send drawRect: to the UIWindow.
Then, set your simulator NSWindow's content view to an instance of that subclass.