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

本文主要是介绍猫猫学iOS之ipad开发Popover的调色板应用_popover显示后其他控件仍然能进行交互,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

猫猫分享,必须精品

原创文章,欢迎转载。转载请注明:翟乃玉的博客
地址:http://blog.csdn.net/u013357243

一:效果

后面的是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

这篇关于猫猫学iOS之ipad开发Popover的调色板应用_popover显示后其他控件仍然能进行交互的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1138332

相关文章

Python中re模块结合正则表达式的实际应用案例

《Python中re模块结合正则表达式的实际应用案例》Python中的re模块是用于处理正则表达式的强大工具,正则表达式是一种用来匹配字符串的模式,它可以在文本中搜索和匹配特定的字符串模式,这篇文章主... 目录前言re模块常用函数一、查看文本中是否包含 A 或 B 字符串二、替换多个关键词为统一格式三、提

Java MQTT实战应用

《JavaMQTT实战应用》本文详解MQTT协议,涵盖其发布/订阅机制、低功耗高效特性、三种服务质量等级(QoS0/1/2),以及客户端、代理、主题的核心概念,最后提供Linux部署教程、Sprin... 目录一、MQTT协议二、MQTT优点三、三种服务质量等级四、客户端、代理、主题1. 客户端(Clien

Golang如何对cron进行二次封装实现指定时间执行定时任务

《Golang如何对cron进行二次封装实现指定时间执行定时任务》:本文主要介绍Golang如何对cron进行二次封装实现指定时间执行定时任务问题,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录背景cron库下载代码示例【1】结构体定义【2】定时任务开启【3】使用示例【4】控制台输出总结背景

SpringBoot开发中十大常见陷阱深度解析与避坑指南

《SpringBoot开发中十大常见陷阱深度解析与避坑指南》在SpringBoot的开发过程中,即使是经验丰富的开发者也难免会遇到各种棘手的问题,本文将针对SpringBoot开发中十大常见的“坑... 目录引言一、配置总出错?是不是同时用了.properties和.yml?二、换个位置配置就失效?搞清楚加

使用Python进行GRPC和Dubbo协议的高级测试

《使用Python进行GRPC和Dubbo协议的高级测试》GRPC(GoogleRemoteProcedureCall)是一种高性能、开源的远程过程调用(RPC)框架,Dubbo是一种高性能的分布式服... 目录01 GRPC测试安装gRPC编写.proto文件实现服务02 Dubbo测试1. 安装Dubb

SpringSecurity显示用户账号已被锁定的原因及解决方案

《SpringSecurity显示用户账号已被锁定的原因及解决方案》SpringSecurity中用户账号被锁定问题源于UserDetails接口方法返回值错误,解决方案是修正isAccountNon... 目录SpringSecurity显示用户账号已被锁定的解决方案1.问题出现前的工作2.问题出现原因各

Python中对FFmpeg封装开发库FFmpy详解

《Python中对FFmpeg封装开发库FFmpy详解》:本文主要介绍Python中对FFmpeg封装开发库FFmpy,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、FFmpy简介与安装1.1 FFmpy概述1.2 安装方法二、FFmpy核心类与方法2.1 FF

基于Python开发Windows屏幕控制工具

《基于Python开发Windows屏幕控制工具》在数字化办公时代,屏幕管理已成为提升工作效率和保护眼睛健康的重要环节,本文将分享一个基于Python和PySide6开发的Windows屏幕控制工具,... 目录概述功能亮点界面展示实现步骤详解1. 环境准备2. 亮度控制模块3. 息屏功能实现4. 息屏时间

CSS中的Static、Relative、Absolute、Fixed、Sticky的应用与详细对比

《CSS中的Static、Relative、Absolute、Fixed、Sticky的应用与详细对比》CSS中的position属性用于控制元素的定位方式,不同的定位方式会影响元素在页面中的布... css 中的 position 属性用于控制元素的定位方式,不同的定位方式会影响元素在页面中的布局和层叠关

SpringBoot3应用中集成和使用Spring Retry的实践记录

《SpringBoot3应用中集成和使用SpringRetry的实践记录》SpringRetry为SpringBoot3提供重试机制,支持注解和编程式两种方式,可配置重试策略与监听器,适用于临时性故... 目录1. 简介2. 环境准备3. 使用方式3.1 注解方式 基础使用自定义重试策略失败恢复机制注意事项