23
TIPS Извадки от xCode проекти Thursday, January 26, 12

iOS Tips + ModalVC

  • Upload
    -

  • View
    762

  • Download
    3

Embed Size (px)

Citation preview

Page 1: iOS Tips + ModalVC

TIPSИзвадки от xCode проекти

Thursday, January 26, 12

Page 2: iOS Tips + ModalVC

BLOCKS & ANIMATIONS

[UIView animateWithDuration:0.3 animations:^{ CGRect newFrame = self.frame; newFrame.origin.y = 0; self.frame = newFrame; self.alpha = 1; shown = YES; } completion:^ (BOOL finished) { if (finished) { //shown = YES; } }];

Thursday, January 26, 12

Page 3: iOS Tips + ModalVC

ANIMATIONS

• когато изпълняваме анимация стойността, която променяме получава новата си стойност незабавно само визуализацията се забавя /в друг thread/

• при прекъсване на анмацията не се изпълнява completion:^

• анимация може да прекъсва друга анимация и да продължава от позицията до която е стигнала

Thursday, January 26, 12

Page 4: iOS Tips + ModalVC

ANIMATIONS- (void)blink { if (shown) return; [UIView animateWithDuration:0.3 animations:^{ CGRect newFrame = self.frame; newFrame.origin.y = 0; self.frame = newFrame; self.alpha = 1; } completion:^ (BOOL finished) { if (finished) { //// Revert image view to original. sleep(3); shown = YES; [self hide:YES]; } }]; [[NSNotificationCenter defaultCenter] postNotificationName:kStatusBarPositionChange object:nil userInfo:[NSDictionary dictionaryWithObject:[NSValue valueWithCGRect:self.frame] forKey:@"frame"]];}

if ([userInfo objectForKey:@"frame"]) {! ! statusBarFrame = [[userInfo objectForKey:@"frame"] CGRectValue];! }

Как да вземем frame от Value

Thursday, January 26, 12

Page 5: iOS Tips + ModalVC

USERINFO

[[NSNotificationCenter defaultCenter] postNotificationName:kStatusBarPositionChange object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSValue valueWithCGRect:self.frame], @"frame", [NSNumber numberWithFloat:animationDuration], @"duration", nil]];

Thursday, January 26, 12

Page 6: iOS Tips + ModalVC

CUSTOM BUTTONS

imgName = [imgName stringByReplacingOccurrencesOfString:@".png" withString:@""];![btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@.png", imgName]] forState:UIControlStateNormal];[btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_high.png", imgName]] forState:UIControlStateHighlighted];

Зареждане на картинки за различни състояния на UIButtonTypeCustom

Thursday, January 26, 12

Page 7: iOS Tips + ModalVC

UISCROLLVIEW

[scrollView scrollRectToVisible:temp animated:NO];

Навигация до определен обект

Thursday, January 26, 12

Page 8: iOS Tips + ModalVC

MODAL VIEWSDifferent view hierarchy

Thursday, January 26, 12

Page 9: iOS Tips + ModalVC

ЗА КАКВО СЕ ИЗПОЛЗВАТ?

• Незабавно събиране на информация от потребителя

• Временно показване на съдържание

• Промяна на работната среда

• Различни интерфейси за различните ориентации

• Нова иерархия от UIView

Thursday, January 26, 12

Page 10: iOS Tips + ModalVC

MODAL VIEWНеобходим е отговор преди потребителят да може да

продължи

Avoid making users scroll through an action sheet. If you include too many buttons in an action sheet, usersmust scroll to see all actions. This is a disconcerting experience for users, because they must spend extra timeconsidering each choice. Also, it can be very difficult for users to scroll without inadvertently tapping a button.

Modal ViewA modal view (that is, a view presented modally) provides self-‐contained functionality in the context of thecurrent task or workflow.

To learn more about defining a modal view in your code, see UIViewController Class Reference .

Appearance and BehaviorA modal view occupies the entire application screen, which strengthens the user’s perception of entering aseparate, transient mode in which they can accomplish something. On iPad, a modal view might also occupythe entire area of a parent view, such as a popover.

A modal view can display text if appropriate, and contains the controls necessary to perform the task. A modalview generally displays a button that completes the task and dismisses the view, and a Cancel button userscan tap to abandon the task.

iOS UI Element Usage GuidelinesAlerts, Action Sheets, and Modal Views

2011-‐10-‐12 | © 2011 Apple Inc. All Rights Reserved.

138

Thursday, January 26, 12

Page 11: iOS Tips + ModalVC

MODALVIEW УПОТРЕБА

TransitionThursday, January 26, 12

Page 12: iOS Tips + ModalVC

Drawing canvas

писане на писмо

ЗА КАКВО СЕ ИЗПОЛЗВА?

Drawing canvas

Help

Organizer

временно представяне

Thursday, January 26, 12

Page 13: iOS Tips + ModalVC

IPAD PRESENTATION STYLES

Figure 9-4 iPad presentation styles

UIModalPresentationFullScreen

UIModalPresentationPageSheet

UIModalPresentationFormSheet

For guidance on when to use the different presentation styles, see “Popover (iPad Only)” in iOS Human InterfaceGuidelines .

Presenting View Controllers From Other View ControllersConfiguring the Presentation Style for Modal Views

2012-‐01-‐09 | © 2012 Apple Inc. All Rights Reserved.

85

Figure 9-4 iPad presentation styles

UIModalPresentationFullScreen

UIModalPresentationPageSheet

UIModalPresentationFormSheet

For guidance on when to use the different presentation styles, see “Popover (iPad Only)” in iOS Human InterfaceGuidelines .

Presenting View Controllers From Other View ControllersConfiguring the Presentation Style for Modal Views

2012-‐01-‐09 | © 2012 Apple Inc. All Rights Reserved.

85

Figure 9-4 iPad presentation styles

UIModalPresentationFullScreen

UIModalPresentationPageSheet

UIModalPresentationFormSheet

For guidance on when to use the different presentation styles, see “Popover (iPad Only)” in iOS Human InterfaceGuidelines .

Presenting View Controllers From Other View ControllersConfiguring the Presentation Style for Modal Views

2012-‐01-‐09 | © 2012 Apple Inc. All Rights Reserved.

85

UIModalPresentationFullScreen UIModalPresentationPageSheet UIModalPresentationFormSheet

Thursday, January 26, 12

Page 14: iOS Tips + ModalVC

IDESK - SEND EMAIL

Thursday, January 26, 12

Page 15: iOS Tips + ModalVC

PRESENT MODALand then presents another view controller (the people picker) in response to that action. Selecting a contact(or canceling the people picker) dismisses that interface and takes the user back to the photo library. Tappingthe Done button then dismisses the photo library and takes the user back to the camera interface.

Figure 9-2 Creating a chain of modal view controllers

Cameraview controller

Photo librarynavigation controller Action sheet People picker

navigation controller

presentmodally

presentmodally

Each view controller in a chain of presented view controllers has pointers to the other objects surrounding itin the chain. In other words, a presented view controller that presents another view controller has valid objectsin both its presentingViewController and presentingViewController properties. You can use theserelationships to trace through the chain of view controllers as needed. For example, if the user cancels thecurrent operation, you could remove all objects in the chain by dismissing the first presented view controller.In other words, dismissing a view controller dismisses not only that view controller but also any view controllersit presented.

In Figure 9-‐2 (page 82), a point worth noting is that the presented view controllers are both navigationcontrollers. You can present UINavigationController objects in the same way that you would present acontent view controller.

When presenting a navigation controller, you always present the UINavigationController object itself,rather than presenting any of the view controllers on its navigation stack. However, individual view controllerson the navigation stack may themselves present other view controllers, including other navigation controllers.

Presenting View Controllers From Other View ControllersAbout View Controller Presentation

2012-‐01-‐09 | © 2012 Apple Inc. All Rights Reserved.

82

Thursday, January 26, 12

Page 16: iOS Tips + ModalVC

TRANSITIONS

PartialCurlVertical slide Flip

Thursday, January 26, 12

Page 17: iOS Tips + ModalVC

NAVIGATION OR MODALКак да изберем?

Thursday, January 26, 12

Page 18: iOS Tips + ModalVC

NAVIGATION / MODAL VIEW

Необходимо е потребителят да въведе текст

Thursday, January 26, 12

Page 19: iOS Tips + ModalVC

NAVIGATION / MODAL VIEW

Thursday, January 26, 12

Page 20: iOS Tips + ModalVC

NAVIGATIONCONTROLLER

push push push

poppoppop

[self.navigationController pushViewController:tableVC animated:YES];

[self.navigationController popViewControllerAnimated:YES];

Thursday, January 26, 12

Page 21: iOS Tips + ModalVC

РАЗЛИКАТА

push push push

poppoppop

present

dismiss

Thursday, January 26, 12

Page 22: iOS Tips + ModalVC

MODALVIEWCONTROLLER

[self presentModalViewController:tableVC animated:YES];

[self dismissModalViewControllerAnimated:YES];

present

dismiss

Thursday, January 26, 12

Page 23: iOS Tips + ModalVC

ЗА СЛЕДВАЩИЯТ ПЪТ

• nsnotification & targets

• blocks

• nstimer

•mapKit

Thursday, January 26, 12