• AJ学IOS 之ipad开发Popover的调色板应用_popover显示后其他控件仍然能进行交互


    AJ分享,必须精品

    一:效果

    后面的是xcode的控制台
    这里写图片描述

    二:代码

    ViewController

    #import "ViewController.h"
    #import "ColorsViewController.h"
    
    @interface ViewController () <ColorsViewControllerDelegate, UIPopoverControllerDelegate>
    - (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.内容
        ColorsViewController *colors = [[ColorsViewController alloc] init];
        colors.delegate = self;
    
        // 1.创建
        self.popover = [[UIPopoverController alloc] initWithContentViewController:colors];
        self.popover.delegate = self;
    
        // 2.显示
    //    [self.popover presentPopoverFromRect:CGRectMake(150, 150, 100, 100) inView:btn.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
        [self.popover presentPopoverFromRect:CGRectMake(924, 668, 100, 100) inView:btn.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    //    [self.popover presentPopoverFromRect:btn.bounds inView:btn permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    //    [self.popover presentPopoverFromRect:btn.frame inView:btn.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    
        // 3.设置哪里控件在popover显示出来的时候,仍旧可以跟用户进行交互
        self.popover.passthroughViews = @[self.greenButton];
    
        self.colorButton = btn;
    }
    
    #pragma mark - 颜色选择代理
    - (void)colorsViewController:(ColorsViewController *)vc didSelectColor:(UIColor *)color
    {
        self.colorButton.backgroundColor = color;
    
        // 关闭popover
        [self.popover dismissPopoverAnimated:YES];
    }
    
    #pragma mark - popover的代理
    - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
    {
        NSLog(@"popover销毁了");
    }
    @end

    ColorsViewController

    #import <UIKit/UIKit.h>
    @class ColorsViewController;
    
    @protocol ColorsViewControllerDelegate <NSObject>
    
    @optional
    - (void)colorsViewController:(ColorsViewController *)vc didSelectColor:(UIColor *)color;
    @end
    
    @interface ColorsViewController : UITableViewController
    @property (nonatomic, weak) id<ColorsViewControllerDelegate> 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
    
  • 相关阅读:
    openlayers方法总结
    AJAX 数据库实例
    AJAX 请求服务器
    得到XMLHttpRequest对象
    AJAX 简介
    AJAX 服务器端的脚本
    HTTP GET 最多发送100个字符
    AJAX XMLHttpRequest 对象
    Dictionary、ArrayList、Hashtable和数组 Array 的区别
    AJAX 请求实例
  • 原文地址:https://www.cnblogs.com/luolianxi/p/4990277.html
Copyright © 2020-2023  润新知