Школа-Студия разработки приложений для iOS. 3 лекция. Интерфейсы, прололжение

  • Published on
    08-May-2015

  • View
    1.714

  • Download
    5

Embed Size (px)

Transcript

  • 1. iOS 3 ,

2. 3. UINavigationController 4. ViewController *c = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:c]; 5. - (IBAction)buttonTapped{UIViewController *c =[[SubViewController alloc] initWithNibName:@"SubViewController"bundle:nil];[self.navigationController pushViewController:c animated:YES];} 6. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{self = [super initWithNibName:nibNameOrNilbundle:nibBundleOrNil];if (self){self.title = @"ViewController";}return self;} 7. UITabBarController 8. 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]; 9. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{self = [super initWithNibName:nibNameOrNilbundle:nibBundleOrNil];if (self){self.title = @"ViewController";self.tabBarItem.image = [UIImageimageNamed:@"1.png"];}return self;} 10. UIPageViewController 11. ViewController *v = [[ViewController alloc] init];[self presentModalViewController:v animated:YES];[self dismissModalViewControllerAnimated:YES]; 12. StoryBoard() 13. View 14. UIAlertViewUIAlertView *a = [[UIAlertView alloc] initWithTitle:@"test"message:@"message" delegate:nilcancelButtonTitle:@"OK"otherButtonTitles:nil];[a show]; 15. UIAlertView- (void)viewDidLoad{UIAlertView *a = [[UIAlertView alloc]initWithTitle:@"test"message:@"message" delegate:selfcancelButtonTitle:@"OK"otherButtonTitles:@"1", @"2", nil];[a show];}- (void)alertView:(UIAlertView *)alertViewclickedButtonAtIndex:(NSInteger)buttonIndex{NSLog(@"%d", buttonIndex);} 16. UIActionSheet 17. UIActionSheet- (void)viewDidLoad{UIActionSheet *s = [[UIActionSheet alloc] initWithTitle:@"test" delegate:selfcancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete"otherButtonTitles:@"One", @"Two", nil];[s showInView:self.view];}- (void)actionSheet:(UIActionSheet *)actionSheetclickedButtonAtIndex:(NSInteger)buttonIndex{NSLog(@"button %d", buttonIndex);} 18. 19. http://mobile-patterns.com 20. Tabs 21. Dashboard 22. UITableView + UINavigationController : 23. Widget 24. News360 25. 26. UIGestureRecognizerUIView:- (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer 27. UITapGestureRecognizerUITapGestureRecognizer *t = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)];t.numberOfTapsRequired = 1;t.numberOfTouchesRequired = 1;[self.view addGestureRecognizer:t]; 28. 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));} 29. UIPinchGestureRecognizerUIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];[self.view addGestureRecognizer:pinch];- (void)pinch:(UIPinchGestureRecognizer *)sender{CGFloat scale = sender.scale;NSLog(@"%g", scale);} 30. UIRotationGestureRecognizerUIRotationGestureRecognizer *r = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];[self.view addGestureRecognizer:r];- (void)rotate:(UIRotationGestureRecognizer *)sender{CGFloat r = sender.rotation;NSLog(@"%g", r);} 31. UISwipeGestureRecognizer *s = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];s.direction = UISwipeGestureRecognizerDirectionLeft;[self.view addGestureRecognizer:s]; UISwipeGestureRecognizer UILongPressGestureRecognizerUILongPressGestureRecognizer *p = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];p.minimumPressDuration = 0.5;[self.view addGestureRecognizer:p]; 32. UIGestureRecognizerDelegate- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizershouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizershouldReceiveTouch:(UITouch *)touch; 33. UIGestureRecognizerStatetypedef enum {UIGestureRecognizerStatePossible,UIGestureRecognizerStateBegan,UIGestureRecognizerStateChanged,UIGestureRecognizerStateEnded,UIGestureRecognizerStateCancelled,UIGestureRecognizerStateFailed,UIGestureRecognizerStateRecognized =UIGestureRecognizerStateEnded} UIGestureRecognizerState; 34. 35. [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]; 36. [UIView beginAnimations:nil context:nil];[UIView setAnimationDelegate:self];[UIView setAnimationDidStopSelector:@selector(animationFinished)];self.view.alpha = 0;[UIView commitAnimations];- (void)animationFinished{//...} 37. The following properties of the UIView class areanimatable:@propertyframe@propertybounds@propertycenter@propertytransform@propertyalpha@propertybackgroundColor@propertycontentStretch 38. 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"); 39. typedef void(^BasicBlock)(void);@property(copy, nonatomic) BasicBlock block;self.block = ^{[self updateWithQuestion];};__weak ViewController *s = self;self.block = ^{[s updateWithQuestion];}; 40. __block NSInteger q = 123; BasicBlock b = ^{ ++q; NSLog(@"%d", q); }; b(); // 124 b(); // 125 41. [UIView animateWithDuration:0.3 animations:^{self.view.alpha = 0;}];[UIView animateWithDuration:0.3 animations:^{ self.view.alpha = 1; } completion:^(BOOL finished) { NSLog(@"animation finished"); }]; 42. [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]; 43. 44. 45. navBar 46. navBar items 47. tabBar 48. tabBar 49. Rich text 50. 51. , UIView? 52. , UIView? UITapGestureRecognizer, addGestureRecognizer. 53. , ? 54. , ? UIView animateWithDuration. , completion . 55. UINavigationBar? 56. UINavigationBar? iOS5 appearance UINavigationBar. iOS4 -(void)drawRect:(CGRect)rect 57. : : webView : , alert /. - modalViewController c 58. gleb34@gmail.com twitter.com/pilot34