Uipopovercontroller is simple and practical

Source: Internet
Author: User
I. Introduction • uipopovercontroller is a common component used in iPad development (which cannot be used on the iPhone). It is very simple to use • uipopovercontroller also Is a controller, Unlike other controllers, it Directly inherited from nsobject, Not inherited from uiviewcontroller • it only occupies part of the screen space to present information, and is displayed at the very beginning of the screen. Step 2: Use

To successfully display a uipopovercontroller, follow these steps:

1> set the content Controller

Because uipopovercontroller directly inherits from nsobject and does not have visualization capabilities, the content above uipopovercontroller must be provided by another controller inherited from uiviewcontroller. This is called "content controller"

You can set the content controller in three ways:-(ID) initwithcontentviewcontroller :( uiviewcontroller *) viewcontroller; When initializing uipopovercontroller, You can input a content controller @ property (nonatomic, retain) uiviewcontroller * contentviewcontroller; use @ property to set the content controller-(void) setcontentviewcontroller :( uiviewcontroller *) viewcontroller animated :( bool) animated; animated can specify whether the content controller should be animated
2> set the size of the content to show the screen space occupied
There are two ways to set the content size: @ property (nonatomic) cgsize popovercontentsize;-(void) setpopovercontentsize :( cgsize) size animated :( bool) animated;
3> set the display position

From where

There are two ways to set the display position:-(void) orientation :( cgrect) rect inview :( uiview *) view permittedarrowdirections ctions :( uipopoverarrowdirection) arrowdirections animated :( bool) animated; this method needs to input a cgrect and a view to set the position pointed by the arrow. The cgrect value is relative to this view, that is, the cgrect uses the top left corner of the view as the coordinate origin (0, 0) for example, if you want an arrow to point to the clicked button, the first method is: [Pop presentpoverfromrect: button. bounds inview: button permittedarrowdirections ctions: uipopoverarrowdirectiondown animated: Yes]; Method 2: [Pop presentpoverfromrect: button. frame inview: button. superview permittedarrowdirections ctions: Required animated: Yes];-(void) returns :( uibarbuttonitem *) item permittedarrowdirections ctions :( optional) arrowdirections animated :( bool) animated; the arrow points to a uibarbut
Iii. Usage notes

1> If the screen of the iPad is rotated and the position displayed by uipopovercontroller may change, you need to rewrite a method of the controller.

-(Void) didrotatefrominterfaceorientation :( uiinterfaceorientation) frominterfaceorientation

In the preceding method, override the position displayed by uipopovercontroller.

 

2> uipopovercontroller and uiactionsheet are a little different. You need to manage the memory by yourself.

U must retain this uipopovercontroller object U in Arc, that is, to reference it with a strong reference • release (call dealloc) before a uipopovercontroller object, you must first dismiss • Use uipopovercontroller correctly under arc (1) use a strong reference (member variable or strong @ property) to save the uipopovercontroller object

_ Pop = [[uipopovercontroller alloc] initwithcontentviewcontroller: VC];

(2) set the delegate of uipopovercontroller to clear the strong reference in the-(void) popovercontrollerdiddismisspopover :( uipopovercontroller *) popovercontroller proxy method

-(Void) popovercontrollerdiddismisspopover :( uipopovercontroller *) popovercontroller

{

_ Pop = nil;

}

3> prevent click to disappear outside the uipopovercontroller Area

• By default, as long as uipopovercontroller is displayed on the screen, all controls behind uipopovercontroller cannot interact with users by default. After you click the control outside the uipopovercontroller area, uipopovercontroller disappears by default. • if you want to click a control outside the uipopovercontroller area, uipopovercontroller does not disappear. The solution is to set the passthroughviews attribute of uipopovercontroller.

@ Property (nonatomic, copy) nsarray * passthroughviews;

This attribute is used to set which controls can continue normal interaction with users when uipopovercontroller is displayed. In this way, the uipopovercontroller will not disappear after you click the control outside the region.

4> appearance

There are two attributes to fine-tune the appearance of uipopovercontroller

@ Property (nonatomic, readwrite) uiedgeinsets popopoverlayoutmargins

This attribute can be used to adjust the display position and set the spacing between the display position and the default display position. For example, uiedgeinsetsmake (0, 0, 0, 40) indicates that the display position is 40 away from the default display position.

@ Property (nonatomic, readwrite, retain) Class popopoverbackgroundviewclass

This attribute can modify the background style of uipopovercontroller. You need to set a subclass class name that inherits uipopoverbackgroundview. The subclass can modify the appearance by implementing corresponding methods.

IV. Other attributes and Methods
@ Property (nonatomic, assign) ID <strong> delegate; uipopovercontroller proxy @ property (nonatomic, readonly, Getter = strong) bool povervisible; uipopovercontroller visible @ property (nonatomic, readonly) uipopoverarrowdirection popopoverarrowdirection; Arrow direction-(void) dismisspopoveranimated :( bool) animated; disabling uipopovercontroller will trigger the corresponding proxy method

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.