Интуит. Разработка приложений для iOS. Лекция 3. Views

  • Published on
    10-May-2015

  • View
    319

  • Download
    5

Transcript

  • 1.Views iOS 3 gleb34@gmail.com

2. 3. "string1" @"string2" 4. "string1" @"string2" Char* NSString* C Objective-C 5. 5 ? 6. 5 ? NSNumber ! @(5) 7. - (void)deleteProfile; 8. , - (void)deleteProfile; 9. ? User *user = ... 10. ? User *user = [[User alloc] init]; User *user = ... 11. Objective-C? 12. Objective-C? NSObject 13. user topic, text - (void)postCommentWithTopic:(NSString *)topic andText:(NSString *)text; 14. user topic, text [user postCommentWithTopic:@"topic" andText:@"text"]; - (void)postCommentWithTopic:(NSString *)topic andText:(NSString *)text; 15. ? @property(nonatomic) NSInteger age; 16. ? getter, setter, @property(nonatomic) NSInteger age; 17. 18. @protocol SendMessageProtocol ! - (void)sendMessage:(NSString *)message; ! @end 19. @interface User : NSObject ! @end @implementation User ! - (void)sendMessage:(NSString *)message { // send message } ! @end 20. id sender = [[User alloc] init]; ! [sender sendMessage:@"message"]; 21. strong weak @interface Car : NSObject ! @property(strong, nonatomic) NSArray *wheels; ! @end ! @interface Wheel : NSObject ! @property(weak, nonatomic) Car *car; ! @end 22. City Venue Country strong strong weak weak 23. http://ru.wikipedia.org/wiki/_(_) 24. CGPoint p; p.x = 10; p.y = 20; p = CGPointMake(10, 20); ! CGSize s; s.width = 100; s.height = 100; s = CGSizeMake(100, 100); ! CGRect r; r.size = s; r.origin = p; r = CGRectMake(10, 20, 100, 100); 25. typedef struct { float x; float y; } Location; ! Location createLocation(float x, float y) { Location l; l.x = x; l.y = y; return l; } ! int main() { Location l = createLocation(1.5, 0.5); printf("location: {%g, %g}", l.x, l.y); } 26. typedef enum { UIViewAnimationCurveEaseInOut, UIViewAnimationCurveEaseIn, UIViewAnimationCurveEaseOut, UIViewAnimationCurveLinear } UIViewAnimationCurve; ! ! ! UIViewAnimationCurve a = UIViewAnimationCurveLinear; printf("%d", a); 27. View 28. iPhone 5: 568px! iPhone 4: 480px 320px 20px 29. UIView @property(nonatomic) CGRect frame; ! @property(nonatomic,readonly) UIView *superview; @property(nonatomic,readonly,copy) NSArray *subviews; ! - (void)removeFromSuperview; - (void)addSubview:(UIView *)view; - (void)bringSubviewToFront:(UIView *)view; - (void)sendSubviewToBack:(UIView *)view; ! @property(nonatomic,copy) UIColor *backgroundColor; @property(nonatomic) CGFloat alpha; @property(nonatomic,getter=isHidden) BOOL hidden; 30. 31. AppDelegate.m 32. Controller 33. UIViewController ! @property(nonatomic,retain) UIView *view; ! - (void)viewDidLoad; ! - (void)viewWillAppear:(BOOL)animated; ! - (void)viewWillDisappear:(BOOL)animated; 34. AppDelegate.m 35. ViewController.m 36. UILabel 37. 38. 39. target, action - (void)viewDidLoad { [super viewDidLoad]; ! [self.button addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside]; } ! - (void)buttonClicked { NSLog(@"buttonClicked"); } 40. delegate - (void)viewDidLoad { [super viewDidLoad]; self.textField.delegate = self; } ! - (BOOL)textFieldShouldReturn:(UITextField *)textField { NSLog(@"return pressed"); } ! @end @interface ViewController : UIViewController 41. @protocol UITextFieldDelegate ! @optional ! - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; - (void)textFieldDidBeginEditing:(UITextField *)textField; - (BOOL)textFieldShouldEndEditing:(UITextField *)textField; - (void)textFieldDidEndEditing:(UITextField *)textField; - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString: (NSString *)string; - (BOOL)textFieldShouldClear:(UITextField *)textField; - (BOOL)textFieldShouldReturn:(UITextField *)textField; ! @end UITextFieldDelegate 42. UIScrollViewDelegate ! @protocol UIScrollViewDelegate ! @optional ! // any offset changes - (void)scrollViewDidScroll:(UIScrollView *)scrollView; ! // any zoom scale changes - (void)scrollViewDidZoom:(UIScrollView *)scrollView __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2); ! // called on start of dragging // (may require some time and or distance to move) - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView; ! ... 43. notications NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; [center postNotificationName:@"UserChanged" object:nil]; NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; [center addObserver:self selector:@selector(userChanged) name:@"UserChanged" object:nil]; ! - (void)userChanged { NSLog(@" "); } : : 44. NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; [center addObserver:self selector:@selector(keyboardShown) name:UIKeyboardDidShowNotification object:nil]; - (void)keyboardShown { NSLog(@"keyboardShown"); } 45. MVC Controller ModelView 46. MVC Controller ModelView 47. MVC Controller ModelView delegates 48. MVC Controller ModelView delegates target,action 49. MVC Controller ModelView delegates target,action 50. MVC Controller ModelView delegates noticationstarget,action 51. views UIButton UITextField 52. , , , , , - 53. ! gleb34@gmail.comtwitter.com/pilot34

Recommended

View more >