Четвертое занятие курса iOS-разработки в ГУ-ВШЭ

Preview:

Citation preview

Разработка приложений для iPhone и iPad

занятие #4

вторник, 12 октября 2010 г.

feedback

вторник, 12 октября 2010 г.

домашнее задание?

вторник, 12 октября 2010 г.

результаты

• Шулюгин Владислав - 10

• Кабир Павел - 10

вторник, 12 октября 2010 г.

а что было?

вторник, 12 октября 2010 г.

события

• Срабатывают при действии пользователя• Посылает action у target

target: myObjectaction: @selector(decrease:)event: UIControlEventTouchUpInside

Пример:

[myControl addTarget:myObject action:@selector(decrease:)forControlEvents: UIControlEventTouchUpInside];

[myControl removeTarget:myObject action:@selector(decrease:)forControlEvents: UIControlEventTouchUpInside];

вторник, 12 октября 2010 г.

view

• прямоугольная часть экрана• показывает и принимает события• view существуют в иерархии: один

superview, много subview

• все view показаны в window

• UIWindow - одно на всё приложение

вторник, 12 октября 2010 г.

иерархия view

• [superView addSubview:view];

• [subView removeFromSuperview];

Либо в IB, либо программно:

Управление иерархией:

- (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;

вторник, 12 октября 2010 г.

view

SuperView производит retain

theView.hidden = YES;

Контроль показа view

вторник, 12 октября 2010 г.

структуры для view

• CGPoint место в пространстве+ { x , y }• CGSize размеры { width , height }• CGRect место и размеры { origin , size }

вторник, 12 октября 2010 г.

Rects, Points and Sizes

CGSizeCGSize

width 144

height 72

CGRectCGRect

origin

size

CGPointCGPoint

x 80

y 54

72

144

80

54

(0, 0) x

y

11Tuesday, January 19, 2010

вторник, 12 октября 2010 г.

работа со структурамиView-related Structure

Creation Function Example

CGPointMake (x, y)CGPoint point = CGPointMake (100.0, 200.0);point.x = 300.0;point.y = 30.0;

CGSizeMake (width, height)CGSize size = CGSizeMake (42.0, 11.0);size.width = 100.0;size.height = 72.0;

CGRectMake (x, y, width, height)

CGRect rect = CGRectMake (100.0, 200.0, 42.0, 11.0);rect.origin.x = 0.0;rect.size.width = 50.0;

12Tuesday, January 19, 2010

синтаксис!(), нет *

наследство от С

вторник, 12 октября 2010 г.

система координат

UIView Coordinate System

+x

+y

0, 0

■ Origin in upper left corner■ y axis grows downwards

13Tuesday, January 19, 2010

вторник, 12 октября 2010 г.

view

frame bounds

координатная система superview

локальная координатная система

используется при использовании view

используется при реализации view

вторник, 12 октября 2010 г.

создаём view

CGRect frame = CGRectMake(20, 45, 140, 21); UILabel *label = [[UILabel alloc] initWithFrame:frame];[window addSubview:label]; [label setText:@”Привет всем!”]; [label release];

вторник, 12 октября 2010 г.

дополнительные бонусы

UIColorUIColor *redColor = [UIColor redColor];[myLabel textColor] = redColor;

UIFontUIFont *font = [UIFont systemFontOfSize:14.0]; [myLabel setFont:font];

вторник, 12 октября 2010 г.

UIImage и UIImageView Создание UIImage:из ресурсов: +[UIImage imageNamed:(NSString *)name]

с диска -[UIImage initWithContentsOfFile:(NSString *)path]

из памяти в виде данных -[UIImage initWithData:(NSData *)data]

UIImage *myImage = [UIImage imageNamed:@’‘oleg.jpg’’];CGRect frame = CGRectMake(20, 45, 140, 21); UIImageView *myImageView = [[UIImageView alloc] initWithFrame:frame];myImageView.image = myImage;[myImage release];

вторник, 12 октября 2010 г.

простая анимация

-(IBAction)changeValue { [UIView beginAnimations:@"advancedAnimations" context:nil]; [UIView setAnimationDuration:0.5]; int value = slider.value; [label setText:[NSString stringWithFormat:@"%d",value]]; CGRect fr = label.frame; fr.origin.y += 40; label.frame = fr; [UIView commitAnimations];}

вторник, 12 октября 2010 г.

посмотрим?

вторник, 12 октября 2010 г.

дизайн приложений в iPhone

Two Flavors of Mail

5Friday, January 22, 2010

вторник, 12 октября 2010 г.

сравниOrganizing Content

6Friday, January 22, 2010

Organizing Content

6Friday, January 22, 2010

вторник, 12 октября 2010 г.

дизайн

• фокус на информацию пользователя

• один функционал единовременно

Organizing Content• Focus on your user’s data• One thing at a time• Screenfuls of content

6Friday, January 22, 2010

вторник, 12 октября 2010 г.

функционал для управленияPatterns for Organizing Content

Navigation Bar Tab Bar

7Friday, January 22, 2010

вторник, 12 октября 2010 г.

MVCParts of a Screenful

Model View

Controller

12Friday, January 22, 2010

вторник, 12 октября 2010 г.

MVC в adress book

Model View

Parts of a Screenful

Controller

11Friday, January 22, 2010

вторник, 12 октября 2010 г.

а зачемMVC?

вторник, 12 октября 2010 г.

вторник, 12 октября 2010 г.

Why Model-View-Controller?• Ever used the word “spaghetti” to describe code?• Clear responsibilities make things easier to maintain

• Avoid having one monster class that does everything

14Friday, January 22, 2010

вторник, 12 октября 2010 г.

Взаимодейтсвие в MVC

• Model не знает про View и Controller, использует notification broadcast

• View не знает про Model и Controller, использует terget-action и делегацию

• Controller знает всех, «мозги» - управление, очень специфичный

вторник, 12 октября 2010 г.

View Controller

• Управляет содержимым экрана

• Наследуй от UIViewController, чтобы определить свою логику

• Несколько ViewController-ов могут совмещаться

“Your” and “Our” View Controllers• Create your own UIViewController subclass for each screenful• Plug them together using existing composite view controllers

View Controller

View Controller

View Controller

NavigationController

25Friday, January 22, 2010

“Your” and “Our” View Controllers• Create your own UIViewController subclass for each screenful• Plug them together using existing composite view controllers

View Controller

View Controller

View Controller

Tab BarController

25Friday, January 22, 2010

вторник, 12 октября 2010 г.

свой ViewController

#import <UIKit/UIKit.h>@interface MyViewController : UIViewController {NSMutableArray *myData; UILabel *myLabel;}

@property (readonly) NSArray *myData;- (void)doSomeAction:(id)sender;

view объявлен в UIViewController

в нашей реализации - loadView

Creating Your View in Code• Override -loadView

■ Never call this directly

• Create your views• Set the view property• Create view controller with -init

// Subclass of UIViewController- (void)loadView{

}

MyView *myView = [[MyView alloc] initWithFrame:frame];

[myView release];self.view = myView; // The view controller now owns the view

29Friday, January 22, 2010

вторник, 12 октября 2010 г.

свой ViewController

- (void)loadView {MyView *myView = [[MyView alloc] initWithFrame:frame];self.view = myView; [myView release];}

вторник, 12 октября 2010 г.

свой ViewController

• File - New File - View Controller

• автоматическое создание nib-файла

• создание нового объекта viewController при помощи -initWithNibName:bundle:

Creating Your View with Interface Builder• Lay out a view in Interface Builder• File’s owner is view controller class• Hook up view outlet• Create view controller

with -initWithNibName:bundle:

30Friday, January 22, 2010

вторник, 12 октября 2010 г.

http://empatika.comoleg.parinov@empatika.com

вторник, 12 октября 2010 г.

Recommended