Leaving Interface Builder Behind
-
Upload
john-wilker -
Category
Technology
-
view
3.346 -
download
0
description
Transcript of Leaving Interface Builder Behind
Leaving Behind
Hello.
• Jake Behrens
• iPhone/Mobile Developer
• UI Designer
Hello.
• Freelancer (as of last Friday!)
Moments
• Choose, but choose wisely.
• Do it for the experience.
30,000 Ft.
Why?
• Knowledge.
• Code reuse.
• Performance.
• Custom = code.
• Tidbits here and there...
A Story
Delegates
Delegates
Outlets
Delegates
Outlets
Location
Time
Code Reuse
Code vs. GUI
CGRect submitButtonFrame = CGRectMake(10.0, 276.0, 300.0, 130.0);UIImage *tempSubmitButtonUp = [UIImage imageNamed:@"SubmitButton_Up.png"];UIImage *tempSubmitButtonDown = [UIImage imageNamed:@"SubmitButton_Down.png"];submitButton = [UIButton buttonWithType:UIButtonTypeCustom];[submitButton setImage:tempSubmitButtonUp forState:UIControlStateNormal];[submitButton setImage:tempSubmitButtonDown forState:UIControlStateHighlighted];[submitButton setFrame:submitButtonFrame];[submitButton addTarget:self action:@selector(submitReport)
forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:submitButton];
Snippets
www.snippetapp.com
Performance
Performance
• Benchmarks.
Performance
• View-based application
Performance
• View-based application
• With IB: 37ms
Performance
• View-based application
• With IB: 37ms
• Without IB: 23ms
Performance
• View-based application w/ UIImageView
Performance
• View-based application w/ UIImageView
• With IB: 47ms
Performance
• View-based application w/ UIImageView
• With IB: 47ms
• Without IB: 25ms
Performance
Performance
Performance
1. Build your app.2. Run
> Run with Performance Tool > Core Animation
Performance
Performance
Performance
• 14 elements in each cell.
Performance
• 14 elements in each cell.
• With IB: 13-23 FPS
Performance
• 14 elements in each cell.
• With IB: 13-23 FPS
• Without IB: 43-60 FPS
Customizing
Iʼm a button!!
Customizing
Iʼm a
button!!
Customizing
[UIView beginAnimations:nil context:nil];[UIView setAnimationDuration:0];[UIView setAnimationDelegate:self];myButton.transform = CGAffineTransformMakeRotation
([Utilities degreesToRadians:45]);[UIView commitAnimations];
Customizing
Iʼm a button!!
Customizing
Iʼm a
button!!
Tidbits & Food 4 Thought
Source Control
<string key="NSFrame">{{20, 20}, {280, 37}}</string>
<string key="NSFrame">{{20, 20}, {280, 37}}</string>
myButton.frame = CGRectMake(20.0, 20.0, 280.0, 37.0);
myButton.frame = CGRectMake(20.0, 20.0, 280.0, 37.0);
Refactor...
• When changing a method name.
• IB doesnʼt fix your action.
Bug Report
• Great opportunity to tell Apple.
“Premature optimization is the root
of all evil.”
So now what?
Tutorials!
View-based Application
Resources
• Remove .xib files.
main.m
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal;}
main.m
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, @”AppDelegate”); [pool release]; return retVal;}
AppDelegate.h
#import <UIKit/UIKit.h>
@class DemoViewController;
@interface AppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; DemoViewController *viewController;}
@property (nonatomic, retain) IBOutlet UIWindow *window;@property (nonatomic, retain) IBOutlet DemoViewController *viewController;
@end
AppDelegate.h
#import <UIKit/UIKit.h>
@class DemoViewController;
@interface AppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; DemoViewController *viewController;}
@property (nonatomic, retain) UIWindow *window;@property (nonatomic, retain) DemoViewController *viewController;
@end
AppDelegate.m
- (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after app launch [window addSubview:viewController.view]; [window makeKeyAndVisible];}
AppDelegate.m
- (void)applicationDidFinishLaunching:(UIApplication *)application { window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];!! viewController = [[DemoViewController alloc] init];! // Override point for customization after app launch [window addSubview:viewController.view]; [window makeKeyAndVisible];}
Custom Xcode Templates
Why?
• Set it up the way you want it.
• Include libraries you use.
Path of Originals
AppDelegate.h
#import <UIKit/UIKit.h>
@class ___PROJECTNAMEASIDENTIFIER___ViewController;
@interface ___PROJECTNAMEASIDENTIFIER___AppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; ___PROJECTNAMEASIDENTIFIER___ViewController *viewController;}
@property (nonatomic, retain) IBOutlet UIWindow *window;@property (nonatomic, retain) IBOutlet ___PROJECTNAMEASIDENTIFIER___ViewController *viewController;
@end
Points of Interest
• Delete the build folder.
• .xcodeproj
Issues with updates...
Path to Customs
http://github.com/withfoam
Graphical Elements In Code
.h
#import <UIKit/UIKit.h>
@interface DemoViewController : UIViewController {! UILabel *displayText;}
@property (nonatomic, retain) UILabel *displayText;
@end
.m#import "DemoViewController.h"
@implementation DemoViewController
@synthesize displayText;
#pragma mark -#pragma mark Application lifecycle
- (void)loadView {! [super loadView];!! displayText = [[UILabel alloc] init];! [displayText setFrame:CGRectMake(20.0, 20.0, 280.0, 30.0)];! [displayText setText:@"Hello 360iDev!"];! [displayText setFont:[UIFont fontWithName:@"Helvetica" size:14.0]];! [self.view addSubview:displayText];}
.m
- (void)dealloc {! [displayText release]; [super dealloc];}
Yay...
.m
- (void)loadView {! [super loadView];!! displayText = [[UILabel alloc] init];! [displayText setFrame:CGRectMake(20.0, 20.0, 280.0, 30.0)];! [displayText setText:@"Hello 360iDev!"];! [displayText setFont:[UIFont fontWithName:@"Helvetica" size:24.0]];! [displayText setBackgroundColor:[UIColor blackColor]];! [displayText setTextColor:[UIColor greenColor]];! [displayText setTextAlignment:UITextAlignmentCenter];! [self.view addSubview:displayText];}
Yay...
UIButton...again.
CGRect submitButtonFrame = CGRectMake(10.0, 276.0, 300.0, 130.0);UIImage *tempSubmitButtonUp = [UIImage imageNamed:@"SubmitButton_Up.png"];UIImage *tempSubmitButtonDown = [UIImage imageNamed:@"SubmitButton_Down.png"];submitButton = [UIButton buttonWithType:UIButtonTypeCustom];[submitButton setImage:tempSubmitButtonUp forState:UIControlStateNormal];[submitButton setImage:tempSubmitButtonDown forState:UIControlStateHighlighted];[submitButton setFrame:submitButtonFrame];[submitButton addTarget:self action:@selector(submitReport) forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:submitButton];
RE:cap
• Increased performance.
• Organization.
• Little things.
Tuts
• Revert apps created for IB.
• Create customized project templates.
• Create graphical elements and objects in code.
Yell at me.
• http://jakebehrens.com
• @withfoam
• http://withfoam.com
• http://github.com/withfoam
Feel lucky?
• R634EJ39MA44
• 77Y7YEL9F6AR
• 3EKR3FAETJPF
• 4KT7EMWHP47P
• EMM4H9XTF6JT
• ERMFPKRR69X6
Hecklers? Questions?