iOS Tips + ModalVC

Preview:

Citation preview

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

Thursday, January 26, 12

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

ANIMATIONS

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

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

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

Thursday, January 26, 12

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

USERINFO

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

Thursday, January 26, 12

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

UISCROLLVIEW

[scrollView scrollRectToVisible:temp animated:NO];

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

Thursday, January 26, 12

MODAL VIEWSDifferent view hierarchy

Thursday, January 26, 12

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

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

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

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

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

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

Thursday, January 26, 12

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

MODALVIEW УПОТРЕБА

TransitionThursday, January 26, 12

Drawing canvas

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

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

Drawing canvas

Help

Organizer

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

Thursday, January 26, 12

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

IDESK - SEND EMAIL

Thursday, January 26, 12

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

TRANSITIONS

PartialCurlVertical slide Flip

Thursday, January 26, 12

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

Thursday, January 26, 12

NAVIGATION / MODAL VIEW

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

Thursday, January 26, 12

NAVIGATION / MODAL VIEW

Thursday, January 26, 12

NAVIGATIONCONTROLLER

push push push

poppoppop

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

[self.navigationController popViewControllerAnimated:YES];

Thursday, January 26, 12

РАЗЛИКАТА

push push push

poppoppop

present

dismiss

Thursday, January 26, 12

MODALVIEWCONTROLLER

[self presentModalViewController:tableVC animated:YES];

[self dismissModalViewControllerAnimated:YES];

present

dismiss

Thursday, January 26, 12

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

• nsnotification & targets

• blocks

• nstimer

•mapKit

Thursday, January 26, 12

Recommended