Курсы по мобильной разработке. 3 лекция. Сложные...

Post on 08-May-2015

1.117 Views

Category:

Education

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Построение интерфейсов(продолжение)

Контроллеры, сложные интерфейсы

Разработка под iOS

Лекция 3

Глеб Тарасов

Сложные контроллеры

UINavigationController

ViewController *c = [[ViewController alloc] initWithNibName:@"ViewController"

bundle:nil];

UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:self.viewController];

- (IBAction)buttonTapped{ UIViewController *c = [[SubViewController alloc] initWithNibName:@"SubViewController" bundle:nil];

[self.navigationController pushViewController:c animated:YES];}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil

bundle:nibBundleOrNil]; if (self) { self.title = @"ViewController"; } return self;}

UITabBarController

ViewController *c = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

SubViewController *s = [[SubViewController alloc] initWithNibName:@"SubViewController" bundle:nil]; UITabBarController *tc = [[UITabBarController alloc] init];

tc.viewControllers = [NSArray arrayWithObjects:c, s, nil];

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil

bundle:nibBundleOrNil]; if (self) { self.title = @"ViewController"; self.tabBarItem.image = [UIImage imageNamed:@"1.png"]; } return self;}

UIPageViewController

StoryBoard(демонстрация)

Варианты интерфейсов

http://mobile-patterns.com

Tabs

Dashboard

UITableView + UINavigationController

Гид Покупок: Продукты

Widget

Клуб Любителей Аудиокниг

Нестандартные интерфейсы

News360

Распознавание жестов

UITapGestureRecognizerUITapGestureRecognizer *t = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)];t.numberOfTapsRequired = 1;t.numberOfTouchesRequired = 1;[self.view addGestureRecognizer:t];

UIPanGestureRecognizerUIPanGestureRecognizer *p = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];[self.view addGestureRecognizer:p];

- (void)pan:(UIPanGestureRecognizer *)sender{ CGPoint t = [sender translationInView:self.view]; CGPoint v = [sender velocityInView:self.view]; NSLog(@"%@", NSStringFromCGPoint(t)); NSLog(@"%@", NSStringFromCGPoint(v));}

UIPinchGestureRecognizerUIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];[self.view addGestureRecognizer:pinch];

- (void)pinch:(UIPinchGestureRecognizer *)sender{ CGFloat scale = sender.scale; NSLog(@"%g", scale);}

UIRotationGestureRecognizerUIRotationGestureRecognizer *r = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];[self.view addGestureRecognizer:r];

- (void)rotate:(UIRotationGestureRecognizer *)sender{ CGFloat r = sender.rotation; NSLog(@"%g", r);}

• UISwipeGestureRecognizer • UILongPressGestureRecognizer

UISwipeGestureRecognizer *s = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];s.direction = UISwipeGestureRecognizerDirectionLeft;[self.view addGestureRecognizer:s];

UILongPressGestureRecognizer *p = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];p.minimumPressDuration = 0.5;[self.view addGestureRecognizer:p];

UIGestureRecognizerDelegate

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer: (UIGestureRecognizer *)otherGestureRecognizer;

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;

UIGestureRecognizerState

typedef enum { UIGestureRecognizerStatePossible,

UIGestureRecognizerStateBegan,

UIGestureRecognizerStateChanged,

UIGestureRecognizerStateEnded,

UIGestureRecognizerStateCancelled, UIGestureRecognizerStateFailed, UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded } UIGestureRecognizerState;

Анимация

[UIView beginAnimations:nil context:nil];[UIView setAnimationDuration:0.5];

self.view.frame = CGRectMake(100, 100, 50, 50);

[UIView commitAnimations];

[UIView beginAnimations:nil context:nil];self.view.alpha = 0;[UIView commitAnimations];

[UIView beginAnimations:nil context:nil];[UIView setAnimationDelegate:self];[UIView setAnimationDidStopSelector:@selector(animationFinished)];

self.view.alpha = 0;

[UIView commitAnimations];

- (void)animationFinished{ //...}

top related