본문 바로가기

PDA&Mobile

아이폰 앱 개발 팁(4) : Stanford Lectures #4-5

* 본 포스트는 Blog.MissFlash.com에서 작성한 것으로, 원문 저작자의 동의없이 마음대로 퍼가실 수 없습니다. 포스트의 내용이 마음에 드시면 링크를 이용해주시면 감사하겠습니다.

> Stanford Lecture #4

* Getters and Setters
- (int)age;
- (void)setAge:(int)age;

* Properties allow access to setters and getters through dot syntax
@property age;
int theAge = person.age;
person.age = 21;

* Various methods of UIApplicationDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application;
- (void)applicationWillTerminate:(UIApplication *)application;

- (void)applicationWillResignActive:(UIApplication *)application;
- (void)application:(UIApplication *)application handleOpenURL:(NSURL *)url;

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application;

* 3 different flavors of action method selector types
- (void)actionMethod;
- (void)actionMethod:(id)sender;
- (void)actionMethod:(id)sender withEvent:(UIEvent *)event;

* Manual Target-Action
@interface UIControl;
- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
- (void)removeTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
@end





> Stanford Lecture #5

* Add/remove views
- (void)addSubview:(UIView *)view;
- (void)removeFromSuperview;

* Manipulate the view hierarchy
- (void)insertSubview:(UIView *)view atIndex:(int)index;
- (void)insertSubview:(UIView *)view belowSubview:(UIView *)view;
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)view;
- (void)exchangeSubviewAtIndex:(int)index withSubviewAtIndex:(int)otherindex;

* 일시적으로 뷰 감추기
myView.hidden = YES;

* View location
CGPoint(x, y);

* View dimension
CGSize(width, height);

* View location and dimension
CGRect(origin, size);

* Manual view creation
CGRect frame = CGRectMake(20, 45, 140, 21);
UILabel *label = [[UILabel alloc] initWithFrame:frame];

[window addSubview:label];
[label setText:@"Number of sides:"];
[label release];

* Defining custom views
- (void)drawRect:(CGRect)rect;

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

* When a view needs to be redrawn, use:
- (void)setNeedsDisplay;

[polygonView setNeedsDisplay];

* Access the graphics context within drawRect: by calling
(CGContextRef)UIGraphicsGetCurrentContext(void);

* 색상 설정
UIColor *redColor = [UIColor redColor];
[redColor set];
// [[UIColor redColor] set] 과 동일

* 폰트 설정
UIFont *font = [UIFont systemFontOfSize:14.0];
[myLabel setFont:font];

* 도형 색 채우기
UIRectFill(square);

* 테두리 색 채우기
UIRectFrame(square);

* 이미지 삽입하는 3가지 방법
+ [UIImage imageNamed:(NSString *)name];
- [UIImage initWithContentsOfFile:(NSString *)path];
- [UIImage initWithData:(NSData *)data];

* Bitmap image example
UIGraphicsBeginImageContext(size);
// drawing code...
result = UIGraphicsGetImageFromCurrentContext();
UIGraphicsEndImageContext();
return result;

* Getting image data
NSData *UIImagePNGRepresentation (UIImage *image);
NSData *UIImageJPGRepresentation (UIImage *image);

* Drawing text & images
- [UIImage drawAtPoint:(CGPoint)point);
- [UIImage drawInRect:(CGRect)rect);
- [UIImage drawAsPatternInRect:(CGRect)rect);
- [NSString drawAtPoint:(CGPoint)point withFont:(UIFont *)font];

* View animation example
- (void)showAdvancedOptions {
[UIView beginAnimations:@"advancedAnimations" context:nil];
[UIView setAnimationDuration:0.3];

// make optionsView visible
optionsView.alpha = 1.0;

// move the polygonView down
CGRect polygonFrame = polygonView.frame;
polygonFrame.origin.y += 200;
polygonView.frame = polygonFrame;

[UIView commitAnimations];
}

* View transforms
CGAffineTransformScale(transform, xScale, yScale);
CGAffineTransformRotate(transform, angle);
CGAffineTransformTranslate(transform, xDelta, yDelta);

* Saving state across app launches
+ (NSUserDefaults *)standardUserDefaults;

- (int)integerForKey:(NSString *)key;
- (void)setInteger:(int)value forKey:(NSString *)key;

- (id)objectForKey:(NSString *)key;
- (void)setObject:(id)value forKey:(NSString *)key;