iOS7 Series –Custom Transitions There is a hierarchy of actors you need to visualize here. It goes a little something like: A TransitioningDelegate An AnimatedTransitioning A ContextTransitioning The VC you start out with and that will call the transition will adopt the first protocol, the TransitioningDelegate Protocol. The purpose of doing so is to obtain the authority to manage the entire transition process. You will then create a Transitioning class which we can call the Transition Manager. This class will adopt the AnimatedTransitioning protocol. The purpose of this protocol is to animate the transition. The Transition Manager class receives all the necessary information from the Transitioning Context (a protocol adopted… Read More
Continue ReadingCreating a Menu in SpriteKit
Cocos2d has a easy to use CCMenu object to which you add CCMenuItems. In SpriteKit however, you are back to UIKit objects. This doesn’t not mean its more complicated, its just different :-). You will need to create a UIControl such as a button or you can use SpriteKit’s SKNode to create the visual object onscreen: SKLabelNode* someNode = [SKLabelNode labelNodeWithFontNamed:@”Chalkduster”]; [someNode setText:@”Play Game”]; [someNode setPosition:CGPointMake(CGRectGetMidX(self.frame)+5,CGRectGetMidY(self.frame)-40)]; [self addChild: someNode]; Now you simply connect the object action to some event like so: for (UITouch *touch in touches) { CGPoint location = [touch locationInNode:self]; if ([someNode containsPoint:location]) { SKTransition* present = [SKTransition revealWithDirection:SKTransitionDirectionDown duration:1]; GameScene* gameScene = [[GameScene alloc] initWithSize:CGSizeMake(1024, 768)]; [self.scene.view… Read More
Continue ReadingSwift Tutorial II
Ok so in the first tutorial we covered let, which is the keyword for defining constants. let thisBeAConstant = 3.141 Now we are going to cover variables, which use the var keyword like so: var thisVariable = time Notice 2 things about Swift: 1) We don’t use ; at the end of a line. That’s just weird 🙂 2) We don’t have to specify the type. The type is inferred by whatever value you pass in, so: var someString = “this is a string” var someInteger = 5 So Swift is kinda smart. Now let’s meet some old friends “Hao jiu bu juan” ARRAYS var energies = [“solar”, “wind”, “fossil”, “this is a… Read More
Continue ReadingFirst SWIFT Tutorial ever! :-)
let is used for assigning constants whereas var is used for creating variables. ie: let salute: Character = “Hey there…” let everyone: Character = “Swift World” var saluteEveryone = salute + everyone saluteEveryone = saluteEveryone + “!”
Continue ReadingCreating a simple UICollectionView in iOS
Steps 1) Create Master-Detail Application & Replace the MasterViewController First we want to create a Master-Detail Application just because it sets up a Master-Detail relationship even though thats the first thing we are going to break :). So go ahead and create a new project in XCode4 based on a Master-Detail Application type. Use ARC, Storyboards and CoreData because we will use CoreData to store information. Your storyboard should look like this: Now select the Master scene until its highlighted in blue and delete it with the Delete key. We simply replace it by dragging in a UICollectionViewController onto the storyboard in its place. This places a UICollectionViewController scene with… Read More
Continue ReadingFirst Google Glass App – Part 8 – Hello Glass!
Jumping right in, let’s create a Glass GDK project from scratch: Create New Android Project Configure GDK Imports Code qwe To create a new project…See our Part 1 of the tutorial. Make sure to configure the Glass GDK Sneak Peek Manually if it didn’t get configured by Android Studio or Eclipse on set up. As it turns out, even if you create a project setting GDK as the Compile for API, it doesn’t get created as such. You must double check in your build.gradle file (CAREFUL, there are 2 such files. You need to modify your inner most gradle file) and make sure it looks something like this: And you… Read More
Continue ReadingFirst Google Glass App – Part 7 – Bridge to Glass App GDK Development
Before jumping into Glass dev, let’s understand how to create a Hello World project in Android Studio (AS) and run it on our device. Create New Project Get to know the guts Add Imports Add Code Tweak guts Run on Device Create New Project When you select New Project from the File Menu, you get this Wizard screen: Fill in the Application Name in a natural language and the Module Name without spaces. Make sure to select API 15 for Minimum and Target SDK but Glass Development Kit Sneak Peek for Compile with. Click Next and in the next screen just leave everything as is (the launch icon selector screen).… Read More
Continue ReadingHow to create an app – Not programmatically
A fellow coder asked: “How does one go about developing an app from scratch? Where does one start?” My response follows: Some will say its a matter of style and you have to find your own. And eventually you will, after a lot of copy-paste programming. I started in 2009 and my first app was a copy-paste of a few different projects. All the app did was connect to the Internet, download XML and parse it into a uilabel. Then I decided to look into more complex app samples. So I downloaded a few from Apple. In particular I remember iPhoneCoreDataRecipes. In hindsight, it was too complex for a beginner… Read More
Continue ReadingObjC Programming
The Big Picture ObjC is OOP which means objects send messages to other objects. Before getting into messages, let’s define objects. Objects. This is very diverse. An object can be a string, a number, a Boolean, an integer, an array, a dictionary or even one you create yourself. There are any types of objects but let’s start at the root object. The root object is called NSObject. You’ll see references to it in code but you’ll hardly ever use it directly. This is called the root object because it’s the starting point of any object. It’s like Adam and Eve rolled into one and ANY other kind of object in… Read More
Continue ReadingFirst Android App – Part 5
My First Android App Android is based on Java much like iOS is based on ObjectiveC. If you are coming from an iOS background, itll be a bit jarring at first. Even though ObjC “comes from” C, C formats are a bit different. So I thought Id start with that first. ObjC: [myObject methodForDoingThis:someParameter]; is a method call which refers to this declared method: -(void)methodForDoingThis: (id)someParameter{ //1. Take the passed in parameter //2. Do something to with that parameter value //3. Call some other method… //4. Or if this were a method that returned an object instead of void //4. Return a new object value } C: myObject.methodForDoingThis(someParameter); is… Read More
Continue ReadingGoogle Glass & Android Series for Developers & Users
So I’ve gotten a little carried away with the Glass-Android thing. My posts are as disorganized as my thoughts, so I thought I’d organize my posts a bit. Here is the set of posts for Android & Glass Development as of Feb 15th, 2014: Google Glass Review – Part 1 – 什么 (shen me = what = what Glass is & isn’t) Google Glass Review – Part 2 – Pros & Cons Develop apps for Google Glass – Part 3 – Setting up! Glass Development Mirror API – Part 4 – Where to start after setting up First Android App – Part 5 First Android App – Part 6 First Google… Read More
Continue ReadingDevelop apps for Google Glass – Part 3 – Setting up!
If you have experience in Android (Java) development, this will be even easier. What you’ll need: Google Glass – to test your apps on Eclipse or Android Studio for coding Android SDK 15 & Glass Development Kit Sneak Peek (GDK) Configure adb Glass Well you either borrow a pair or get your own, but you will need Google Glass to test your apps. The reason being that there is no Glass emulator as there is for Android as of yet. Eclipse or Android Studio Eclipse is the most widely known IDE for Android programming but its worth getting to know Android Studio, the new IDE for developing on Android &… Read More
Continue ReadingWWDC 2013 Videos of Interest
WWDC 2013 Videos of Interest Introducing Text Kit Advanced Text Layouts & Effects with TextKit Building User Interfaces in iOS7 Custom Transitions Using View Controllers Customizing Your App’s Appearance for iOS 7 Introduction to Sprite Kit Designing Games with Sprite Kit Getting Started with UIKit Dynamics What’s New in iOS User Interface Design Pretty much all the Whats New…
Continue ReadingNSOperationQueue & NSInvocationOperation
1. In your main class’ init method call this: operationQueue = [[NSOperationQueue alloc]init]; [operationQueue setMaxConcurrentOperationCount:1]; 2. Then in your viewWillAppear you can call this: [self showLoadingIndicators]; //calls a method which presents loading indicators (optional) [self beginLoadingTwitterData]; // this is the method that fires it all off 3. In your beginLoadingTwitterData you call this: NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(synchronousLoadTwitterData) object:nil]; [operationQueue addOperation:operation]; // creates and adds NSOperation to a queue [operation release]; 4. In this synchronousLoadTwitterData is where you do the heavy lifting: NSDictionary *dict = [[NSDictionary alloc] initWithDictionary:[TwitterHelper fetchInfoForUsername:[twitterIds objectAtIndex:count]]] // this calls for a method “fetchInfoForUsername” which returns an NSDictionary, but to do so, it connects to… Read More
Continue ReadingGrandCentralDispatch & Blocks
GCD helps improve your apps performance and responsiveness by outsourcing processes that require a lot or computing power to the background while keeping your UI responsive. Normally you might want to do some heavy lifting. Let’s create an Empty Application. You need to declare a IBOutlet UIImageView *imageView ivar in your appDelegate, make it a property and synthesize it in .m and make the connection in Interface Builder, IB. In it’s viewDidLoad method put the following code: // Download the image NSURL *url = [NSURL URLWithString:@”http://www.santiapps.com/assets/bbkoko.jpg”]; NSURLRequest *req = [NSURLRequest requestWithURL:url]; NSURLResponse *res = [[NSURLResponse alloc] init]; NSError *err = nil; NSData *data = nil; data = [NSURLConnection sendSynchronousRequest:req returningResponse:&res… Read More
Continue ReadingNSOperation
Lets say you are not only downloading tweets (text) from the web, but actual chunks of raw data, such as images. You may have a method that returns a UIImage, such as: -(UIImage*)cachedImageForURL:(NSURL*)url{ //Preferably look for a cached image id cachedObject = [cachedImages objectForKey:url]; if (cachedObject == nil) { //set loading placeholder in our cache dict [cachedImages setObject:LoadingPlacedholder forKey:url]; //Create and queue a new image loading op ImageLoadingOp *operation = [[ImageLoadingOp alloc] initWithImageURL:url target:self action:@selector(didFinishLoadingImageWithResult:)]; [operationQueue addOperation:operation]; [operation release]; } else if(![cachedObject isKindOfClass:[UIImage class]]) { //were already loading the image, dont kick off another request cachedObject = nil; } return cachedObject; } Except notice this time the operation is not… Read More
Continue ReadingiOS Indie Developer/Programmer Evolution
These are just random thoughts on what I believe are the pros and cons of coding an app vs a game. The reason why I am writing this is actually because I find myself in the same predicament. I’ve been coding crap for the past 3 years and I believe its time to make something “significant”. At first I thought, I’ll code a bunch of apps and even though they might not be Top Pick apps, they will be enough. Even if they only make about $5-$10 a month, I may be reaping $100 a month which sounds cool. I even got into the whole iAds thing and thought it… Read More
Continue ReadingHow to Read iOS or Mac OS Programming Documentation
The toughest part for me to get started was reading the Apple Documentation on iOS or MacOS. When I got into more APIs it got more complex. You need to understand how to read API or proprietary code documents in order to understand how to create a piece of code, connect to web services or debug changes in code. You will very often see the term DEPRECATED, which means a particular method name is no longer used. This is very important so let’s take a look at Apple Docs first: This tells us that the object of type NSArray has many methods that you can call on it. They may… Read More
Continue ReadingPassing Data Example
Delegates or Properties, take your pick. PROPERTIES Class A (ViewController) wants to communicate with Class B (ViewController) Before calling Class B, do the following: In Class B, create a @property NSString* receivedValue; In Class A, #import Class B then in the method that calls B (either prepareForSegue or didSelectRowAtIndexPath or some method where you present Class B view controller, do the following: Class B *calledVC = alloc/init calledVC.receivedValue = ‘whatever value you want to pass’; then call Class B VC Done! DELEGATES Let’s say Class B wants to notify Class A that something has finished. In Class B add this above your @interface: @protocol YourDelegateProtocol <NSObject> – (void)itemWillBePassed; @end… Read More
Continue ReadingUsing NSUserDefaults
This is handy when saving credentials to a device so the user doesn’t have to re-login every time he launches the app. NOTE: This is not useful for saving large amounts of data or data that will change frequently. Use iCloud or persistent state stores such as databases or xml or plist files for that! Once you have the data you wish to save somewhere in your app, call the following: // call the store object NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; // set an object for it [prefs setObject:imageView.image forKey:@”keyToLookupImage”]; // call sync to save it [prefs synchronize]; then later in the beginning or launch of an app you can… Read More
Continue ReadingNSCoding & NSUserDefaults to store something simple…
Lets say you created an app which lets you select a person from the Address Book and you wish to set that person as the default user to use each time you launch the app. You want to store that preference in NSUserDefaults. If there is a lot of data to that person, you probably don’t want to store each key, key by key…This is where you can modify your NSObject class to conform to NSCoding and quickly save & load your data. 1. In you NSObject Class add theprotocol. @interface CustomObject : NSObject <NSCoding> 2. Now add these 2 methods to your NSObject Class: – (void) encodeWithCoder:(NSCoder*)encoder; – (id)… Read More
Continue ReadingHow to mask a UIImage in iOS
– (void)viewDidLoad { [super viewDidLoad]; UIImage *imageToMask = [UIImage imageNamed:@”koko.jpg”]; UIImageView *imageToMaskImgView = [[UIImageView alloc] initWithImage:imageToMask]; CGRect imgRect = CGRectMake(0, 0, imageToMaskImgView.frame.size.width, imageToMaskImgView.frame.size.height); UIView *maskMaster = [[UIView alloc] initWithFrame:imgRect]; [maskMaster setBackgroundColor:[UIColor whiteColor]]; [maskMaster addSubview:imageToMaskImgView]; UIGraphicsBeginImageContext(maskMaster.bounds.size); [maskMaster.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSLog(@”%@ is the view image”, viewImage); UIImage *bFooImg = [UIImage imageNamed:@”blackapple.png”]; self.myPic.image = [self maskImage:bFooImg withMask:viewImage]; } – (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage { CGImageRef maskRef = maskImage.CGImage; CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef), CGImageGetHeight(maskRef), CGImageGetBitsPerComponent(maskRef), CGImageGetBitsPerPixel(maskRef), CGImageGetBytesPerRow(maskRef), CGImageGetDataProvider(maskRef), NULL, false); CGImageRef masked = CGImageCreateWithMask([image CGImage], mask); //memman CGImageRelease(mask); CGImageRelease(maskRef); return [UIImage imageWithCGImage:masked]; }
Continue ReadingOreilly Learning iPhone Programming
Currently on Ch5 but have a few questions looming in the back of my mind: 1) Why use a tableviewcell to enter data for AddNewCity instead of a UIView with label and description? 2) Just as i thought, tag 777 got me in trouble. My bad because i added the tag to both the inner component uitextField and the outer component tableViewCell by mistake. But im wondering a couple of things: (a) can i tag the entire structure uitableViewCell as i did (without tagging the inner components) and get any component inside it with that tag refrence? (b) why exactly was it not passing the data correctly; because the outer… Read More
Continue ReadingDelegates & Protocols iOS
A complex subject to wrap your head around, i agree! But its pretty cool once you get a working example going. Let’s think of a game where a lander comes down from the sky (presumably on Mars – since Mars is a hot topic lately) and deploys a rover. In Cocos2d, you put all your objects on a Layer object. This means the layer class is the main class (analogous to a viewcontroller class contains buttons, views, labels, cells etc). You create a Lander object class because you want to re-use it everywhere in the game. With every new level, you must create a new layer class but you can… Read More
Continue ReadingiPhoneCoreDataRecipes Explained…
Im going thru this Apple app and im noting my progress in understanding it. Any comments are appreciated. black = unanswered questions red = my answers so far blue = partially answered on the blog itself green = less important, design questions maybe… RecipeListTableViewController.m 1) Why @class Recipe and @class RecipeTableViewCell 2) They adopt a RecipeAddDelegate & NSFetchedResultsControllerDelegate protocols? YES…Ive never seen a protocol before. I guess the NSFRC protocol class is a UIKit class but i had never seen a customcreated class be used as a protocol…COOL! 3) Why do we declare showRecipe & configureCell methods but not the add:method or the whole bunch of others…. 4) When creating… Read More
Continue ReadingStanford Assignment 3 HelloPoly: 1 Control/Multiple Actions
I should have known this from my experience in Flash! The solution to why it only draws the first polygon is that the same buttons, Increase and Decrease, required multiple, in this case 2, actions, not just one. Basically you need to define another method, inside the polygonview, which calls setNeedsDispaly. And hook up the same buttons in the nib file to that method.
Continue Reading