Weitere ähnliche Inhalte Ähnlich wie Школа-Студия разработки приложений для iOS. 3 лекция. Интерфейсы, прололжение (20) Mehr von Глеб Тарасов (16) Школа-Студия разработки приложений для iOS. 3 лекция. Интерфейсы, прололжение5. ViewController *c = [[ViewController alloc]
initWithNibName:@"ViewController"
bundle:nil];
UINavigationController *nc =
[[UINavigationController alloc]
initWithRootViewController:c];
6. - (IBAction)buttonTapped
{
UIViewController *c =
[[SubViewController alloc]
initWithNibName:@"SubViewController"
bundle:nil];
[self.navigationController pushViewController:c
animated:YES];
}
11. 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];
12. - (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;
}
18. UIAlertView
UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"test"
message:@"message"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[a show];
19. UIAlertView
- (void)viewDidLoad
{
UIAlertView *a = [[UIAlertView alloc]
initWithTitle:@"test"
message:@"message"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:@"1", @"2", nil];
[a show];
}
- (void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"%d", buttonIndex);
}
21. UIActionSheet
- (void)viewDidLoad
{
UIActionSheet *s = [[UIActionSheet alloc] initWithTitle:@"test"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Delete"
otherButtonTitles:@"One", @"Two", nil];
[s showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"button %d", buttonIndex);
}
32. UIPanGestureRecognizer
UIPanGestureRecognizer *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));
}
35. UISwipeGestureRecognizer *s = [[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:@selector(pan:)];
s.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:s];
• UISwipeGestureRecognizer
• UILongPressGestureRecognizer
UILongPressGestureRecognizer *p = [[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:@selector(pan:)];
p.minimumPressDuration = 0.5;
[self.view addGestureRecognizer:p];
37. UIGestureRecognizerState
typedef enum {
UIGestureRecognizerStatePossible,
UIGestureRecognizerStateBegan,
UIGestureRecognizerStateChanged,
UIGestureRecognizerStateEnded,
UIGestureRecognizerStateCancelled,
UIGestureRecognizerStateFailed,
UIGestureRecognizerStateRecognized =
UIGestureRecognizerStateEnded
} UIGestureRecognizerState;
39. [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];
41. The following properties of the UIView class are
animatable:
@property frame
@property bounds
@property center
@property transform
@property alpha
@property backgroundColor
@property contentStretch
42. Блоки
void(^b)(void) = ^{
NSLog(@"test");
};
b();
NSInteger(^c)(CGFloat, NSString *) = ^(CGFloat p, NSString *s){
NSLog(@"test %g %@", p, s);
return 10;
};
NSInteger q = c(10.5, @"abc");
45. Анимация с блоками
[UIView animateWithDuration:0.3 animations:^{
self.view.alpha = 0;
}];
[UIView animateWithDuration:0.3
animations:^{
self.view.alpha = 1;
}
completion:^(BOOL finished) {
NSLog(@"animation finished");
}];
46. Удобства с блоками
[BlockAlertView showTitle:@"Ошибка"
text:@"Для изменения личных данных необходимо подключение к интернету."
cancelButton:@"ОК"
action:^{
[s.navigationController dismissModalViewControllerAnimated:YES];
}];
DDXMLElement *style = [[img.attributes where:^BOOL(id element) {
DDXMLNode *attr = element;
return [attr.name isEqualToString:@"style"];
}] firstObject];
BlockTapGestureRecognizer *tap = [[BlockTapGestureRecognizer alloc] initWithAction:^{
[self dismissModalViewControllerAnimated:YES];
}];
[self.view addGestureRecognizer:tap];
56. Что нужно сделать, чтобы
распознать нажатие на UIView?
Создать UITapGestureRecognizer,
добавить его через addGestureRecognizer.
57. Как по нажатию на кнопку анимированно передвинуть
эту кнопку в другой угол экрана, а в конце анимации
изменить ее цвет?
58. Как по нажатию на кнопку анимированно передвинуть
эту кнопку в другой угол экрана, а в конце анимации
изменить ее цвет?
С помощью метода UIView animateWithDuration.
В блоке анимации изменить фрейм,
в блоке completion изменить цвет.
59. Как во всем приложении поменять фон у
UINavigationBar?
60. Как во всем приложении поменять фон у
UINavigationBar?
Для iOS5 достаточно воспользоваться статическим
свойством appearance у UINavigationBar.
Для iOS4 надо создать категорию и подменить метод -
(void)drawRect:(CGRect)rect
61. Задание
• два таба
• список городов из файла
• при выборе строки: карта с
указанием на этот город
• список сайтов из файла
• при выборе строки: страница
в webView с этим сайтом
На всех экранах:
Кнопка «Инфо», по нажатию alert с вопросом «да/нет». Если да - открывается
modalViewController c текстом «об авторе»
62. Спасибо
Глеб Тарасов
gleb34@gmail.com
twitter.com/pilot34