Development of Popover's color palette app on iOS ipad _ other widgets can still interact after popover is displayed

Source: Internet
Author: User

Development of Popover's color palette app on iOS ipad _ other widgets can still interact after popover is displayed

 

I. Effect

The following is the xcode console.

Ii. Code ViewController
# Import ViewController. h # import ColorsViewController. h @ interface ViewController ()
  
   
-(IBAction) buttonClick :( UIButton *) btn; @ property (nonatomic, weak) UIButton * colorButton; @ property (nonatomic, strong) UIPopoverController * popover; @ property (weak, nonatomic) IBOutlet UIButton * greenButton;-(IBAction) greenButtonClick; @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad];}-(IBAction) greenButtonClick {NSLog (@ greenButtonClick);}-(IBAction) buttonClick :( UIButton *) btn {// 0. content ColorsViewController * colors = [[ColorsViewController alloc] init]; colors. delegate = self; // 1. create self. popover = [[UIPopoverController alloc] initWithContentViewController: colors]; self. popover. delegate = self; // 2. display // [self. popover presentpoverfromrect: CGRectMake (150,150,100,100) inView: btn. superview permittedArrowDirections ctions: UIPopoverArrowDirectionAny animated: YES]; [self. popover presentpoverfromrect: CGRectMake (924,668,100,100) inView: btn. superview permittedArrowDirections ctions: UIPopoverArrowDirectionAny animated: YES]; // [self. popover presentpoverfromrect: btn. bounds inView: btn permittedArrowDirections: UIPopoverArrowDirectionAny animated: YES]; // [self. popover presentpoverfromrect: btn. frame inView: btn. superview permittedArrowDirections ctions: UIPopoverArrowDirectionAny animated: YES]; // 3. set where controls can still interact with users when popover displays them. popover. passthroughViews = @ [self. greenButton]; self. colorButton = btn;} # pragma mark-color selection proxy-(void) colorsViewController :( ColorsViewController *) vc didSelectColor :( UIColor *) color {self. colorButton. backgroundColor = color; // disable popover [self. popover dismissPopoverAnimated: YES] ;}# pragma mark-popover proxy-(void) handle :( UIPopoverController *) popoverController {NSLog (@ popover destroyed);} @ end
  
ColorsViewController
#import 
  
   @class ColorsViewController;@protocol ColorsViewControllerDelegate 
   
    @optional- (void)colorsViewController:(ColorsViewController *)vc didSelectColor:(UIColor *)color;@end@interface ColorsViewController : UITableViewController@property (nonatomic, weak) id
    
      delegate;@end
    
   
  
#import ColorsViewController.h@interface ColorsViewController ()@end@implementation ColorsViewController- (void)viewDidLoad {    [super viewDidLoad];    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}#pragma mark - Table view data source- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {    return 30;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    static NSString *ID = @cell;    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];    if (!cell) {        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];        cell.selectionStyle = UITableViewCellSelectionStyleNone;    }    cell.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1.0];    return cell;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    if ([self.delegate respondsToSelector:@selector(colorsViewController:didSelectColor:)]) {        UIColor *color = [tableView cellForRowAtIndexPath:indexPath].backgroundColor;        [self.delegate colorsViewController:self didSelectColor:color];    }}@end

 

Related Article

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.