IOS_21 group_pover for iPad horizontal and vertical screen Switching

Source: Internet
Author: User

IOS_21 group_pover for iPad horizontal and vertical screen Switching

Finally:



Code snippet: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Vc3ryb25np1_vcd4kpha + PHByZSBjbGFzcz0 = "brush: java;"> /// DockItemLocation. m // handsome _ buy /// Created by beyond on 14-8-13. // Copyright (c) 2014 com. beyond. all rights reserved. // # import "DockItemLocation. h "// click locationBtn on the dock. The Popover encapsulated controller is displayed. The search bar is displayed at the top and tableView # import" CityLocationController at the bottom. h "// The button above is an image, and below is text, which is the ratio of the Image Height # define kImageHeightRatioInBtn 0.5 @ interface DockItemLocation () {// Popover controller. After the controller is created, the show method is displayed. Therefore, it cannot be a local variable and must be remembered using the member variable. Otherwise, the method btnClick is destroyed after being called, how can I display the pinch? UIPopoverController * _ popoverCtrl;} @ end @ implementation DockItemLocation-(id) initWithFrame :( CGRect) frame {self = [super initWithFrame: frame]; if (self) {// 1. call the method of the parent class and set the internal image [self setIcon: @ "ic_district.png" selectedIcon: @ "ic_district_hl.png"]; // 2. auto scaling self. autoresizingMask = UIViewAutoresizingFlexibleTopMargin; // 3. set the default text [self setTitle: @ "中"" forState: UIControlStateNormal]; self. titleLabel. f Ont = [UIFont systemFontOfSize: 16]; self. titleLabel. textAlignment = NSTextAlignmentCenter; [self setTitleColor: [UIColor whiteColor] forState: UIControlStateDisabled]; [self setTitleColor: [UIColor grayColor] forState: UIControlStateNormal]; // 4. set image attributes self. imageView. contentMode = UIViewContentModeCenter; // 5. click [Location] to display a Popover controller [self addTarget: self action: @ selector (locationBtnOnDockClic Ked) forControlEvents: UIControlEventTouchDown];} return self;} // 5. click [Location] for the listener. A Popover controller (void) locationBtnOnDockClicked {// disabled. You can click self only once. enabled = NO; // click locationBtn on the dock. The Popover encapsulated controller is displayed. The search bar is displayed at the top, and tableView CityLocationController * cityVC = [[CityLocationController alloc] init] at the bottom. // The only controller that does not inherit from UIViewController. It inherits from NSObject // popover controller. After the controller is created, the show method is displayed. Therefore, it cannot be a local variable, the member variables must be remembered; otherwise, Method B After tnClick is called, it will be destroyed. How can I display the pinch? _ PopoverCtrl = [[UIPopoverController alloc] initWithContentViewController: cityVC]; // set the display size of the Popover controller _ popoverCtrl. popoverContentSize = CGSizeMake (320,480); // proxy, listen to the XX Event _ popoverCtrl of the Popover controller. delegate = self; // because other methods need to be displayed, _ popoverCtrl is selected as the custom method [self showPopoverCtrl]; // when the screen is rotated, the position pointed to by the pop-up popover is incorrect. Therefore, it is necessary to register a notification to listen to the screen rotation. // remove the listener first to ensure robustness [[nsicationicationcenter defacenter center] removeObserver: sel F name: jsonobject: nil]; // Add another listener. Once the device has a UIDeviceOrientationDidChangeNotification, the system calls the [[nsicationicationcenter ultcenter] addObserver: self selector: @ selector (screenDidRotated) name: UIDeviceOrientationDidChangeNotification object: nil];} // 5-1, because the screen is rotated, _ popoverCtrl must be displayed again, so the custom method-(void) showPopoverCtrl {// Where is the display? If the target view is self, the rect uses bounds because the origin of bounds is relative to itself. // if the target view is self. superView, The rect uses frame, because the origin of the frame is relative to the parent control [_ popoverCtrl presentpoverfromrect: self. bounds inView: self permittedArrowDirections ctions: UIPopoverArrowDirectionAny animated: YES];} // 5-2. Add another listener. Once the listener appears on the device, the selector method (void) of the observer is called) screenDidRotated {if (_ popoverCtrl. popoverVisible) {// 1. close the _ popoverCtrl [_ poverctrl dismissPopoverAnimated: NO] above the previous position; // 2. after 0.5 seconds, create the _ popoverCtrl [self owned mselector: @ selector (showpoverctrl) withObject: nil afterDelay: 0.5] ;}# pragma mark-popOver proxy method-(void) popoverControllerDidDismissPopover :( UIPopoverController *) before the popoverController {// disappears, let the locate button restore and click the status self. enabled = YES; // before the message disappears, that is, when the popover is destroyed, the registered listener (notification) [[[nsicationicationcenter defacenter center] removeObserver: self name: UIDeviceOrientationDidChangeNotification object: nil] is removed;} # When pragma mark is destroyed, the current screen listening to the Controller is removed to prevent the wild pointer-(void) dealloc {[[nsicationicationcenter defacenter center] removeObserver: self];} # pragma mark-Override adjust image and text in the Frame-(CGRect) imageRectForContentRect :( CGRect) contentRect {CGFloat btnW = contentRect. size. width; CGFloat imgH = contentRect. size. height * weight; return CGRectMake (0, 0, btnW, imgH);}-(CGRect) titleRectForContentRect :( CGRect) contentRect {CGFloat btnW = contentRect. size. width; CGFloat textH = contentRect. size. height * (1-kImageHeightRatioInBtn); // The text is below, and the image is above CGFloat textY = contentRect. size. height-textH; return CGRectMake (0, textY, btnW, textH);} @ end






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.