Use of IOS Uipopovercontroller

Source: Internet
Author: User

1. What is Uipopovercontroller?

is a common controller in ipad development (not allowed on iphone)

Unlike other controllers, it inherits directly from NSObject and does not inherit from Uiviewcontroller

It takes up only a portion of the screen space to present information and is displayed at the front of the screen

2. How do I use Uipopovercontroller?

2.1 Use of ideas (preliminary)

1> Create a Uipopover

2> Determining content

3> Setting Dimensions

Where does the 4> show up?

2.2 Sample Code One

//Create a uipopover

Uipopovercontroller *pop = [[Uipopovercontroller alloc]init];

//Determine content

Qktableviewcontroller *QKTB = [[Qktableviewcontroller alloc]init];

Pop.contentviewcontroller = QKTB;

Set Dimensions

Pop.popovercontentsize = Cgsizemake (320, 160);

//Where to come from, Sender is -(Ibaction) menu: (ID) Sender parameter, this method is called when the Uibarbuttonitem of the navigation controller is clicked

[Pop Presentpopoverfrombarbuttonitem:sender Permittedarrowdirections:uipopoverarrowdirectionany Animated:YES];

Run the program error, the cause of the error is as follows, so uipopover at the time of creation, it must be set Contentviewcontroller

  Reason: '-[uipopovercontroller init] is not a valid initializer. You must call-[uipopovercontroller Initwithcontentviewcontroller:]. '

2.3 Example code two to resolve an issue with popover illegal initialization 

Get the Content

Qktableviewcontroller *QKTB = [[Qktableviewcontroller alloc]init];

Create a Uipopover

Uipopovercontroller *pop = [[Uipopovercontroller ALLOC]INITWITHCONTENTVIEWCONTROLLER:QKTB];

Set Dimensions

Pop.popovercontentsize = Cgsizemake (320, 160);

Where do you come from?

[Pop Presentpopoverfrombarbuttonitem:sender Permittedarrowdirections:uipopoverarrowdirectionany Animated:YES];

Run the program in IOS7 error, error reasons are as follows, so uipopover in the creation, it must be set Contentviewcontroller, because the pop is a local variable, the method is released after execution, the solution is to engage in a strong reference, IOS8 was sure that every popover had a strong reference to keep it alive.

 reason: '-[uipopovercontroller dealloc] reached while popover is still visible. ' //When PopOver still shows, it's released.

running the program in IOS8 is normal. The description of Apple in the iOS8 for PopOver has a special optimization, reducing the amount of code.

 The way to resolve crashes in iOS7 is to strengthen the reference

Self.popover = Pop;

2.4 Example code Three

Set the size, if the size of the code is commented out, the default size of PopOver is 320x493 (popover Triangle occupies 13 of the height)

Pop.popovercontentsize = Cgsizemake (320, 160);

2.5 Example Code Four

//In Contentviewcontroller's Viewdidload set the size in

  Self.contentsizeforviewinpopover = cgsizemake (100, 100); This property can be used before//iOS6 or IOS6, the property is obsolete in iOS7, but used in iOS7 is still valid and invalid in iOS8

Self.preferredcontentsize = Cgsizemake (150, 150); ///IOS7 or iOS7 This property is recommended after iOS7, so this involves the version adaptation of Ios6\7\8.

  2.6 Example Code Five

Uipopover can point to any view, the following 2 lines of code are equivalent

  [Pop presentpopoverfromrect:self.myBtn.bounds inview:self.mybtn permittedarrowdirections: Uipopoverarrowdirectionany Animated:yes];

  [Pop presentpopoverfromrect:self.myBtn.frame inview:self.myBtn.superview Permittedarrowdirections:uipopoverarrowdirectionany Animated:yes];

  2.7 Example code six

Uipopover also has a proxy method

Pop.delegate = self;

Self adheres to <UIPopoverControllerDelegate> protocols to implement protocol methods

//Decide whether to click on the mask, popover can disappear

-(BOOL) Popovercontrollershoulddismisspopover: (Uipopovercontroller *) Popovercontroller;

After the popover disappears, call the following proxy method,

Note: If popoer disappears due to the execution of this line of code [pop Dismisspopoveranimated:bool], the following proxy method will not be executed

-(void) Popovercontrollerdiddismisspopover: (Uipopovercontroller *) Popovercontroller;

PopOver position change, for example, the screen switch, call the following proxy method

-(void) Popovercontroller: (Uipopovercontroller *) Popovercontroller willrepositionpopovertorect: (inout CGRect *) rect InView: (inout UIView * *) View Ns_available_ios (7_0);

2.8 Example Code Seven

 Penetrate masks, click mybtn and MyBtn2 areas,

Pop.passthroughviews = @[self.mybtn,self.mybtn2];

2.9 Thinking of using uipopover (final)

1> Create a Uipopover (set Contentviewcontroller at the same time as created)

Where does the 2> show up?

As far as its size is best not to write dead, preferably by Contentviewcontroller decision, so use uipopover as long as the above 2 steps can

3. Summary:

Why do I need to determine content with Uipopover?

Because Uipopover inherits from NSObject, it does not have a display function like Uiview\uiviewcontroller.

Why do I need to be sure where to show it from using Uipopover?

Like the UIView frame, the light has a size, and it is not possible to set origin.

Image understanding:

1> can compare uipopover to a picture frame

2> the middle of the show what content is determined by the photo

3> can buy the picture frame (fixed size) First, cut the photos into.

4> can also wash the photos first, and then according to the size of the photos to buy photo frames (size determined by the photo)

5> picture frame, you need to consider hanging the frame.

Use of IOS Uipopovercontroller

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.