- 浏览: 763383 次
- 性别:
- 来自: 天堂
文章分类
最新评论
-
xiaozhao-521:
呀呀呀呀呀呀呀
RequestTest222 -
Andy_hyh:
打扰了,问下openmeeting源码可以运行起来吗?
Openmeetings安装 详细步骤 -
qindongliang1922:
擦,现在还行么,厉害
北京免费吃饭的地方 -
minixx77:
...
Openmeetings安装 详细步骤 -
wwwqqqiang:
喜欢楼主分享问题的方式,有思想
UIView 和 CALayer的那点事
一:模态视图
UIActionSheet、UIAlertView、GKPeerPickerController、UIAPopover、GKPanel等都是ios系统自带
的模态视图。
模态视图的一个重要的特性就是在显示模态视图的时候可以阻断其他视图的事件响应。
该特性在有些时候对我们是非常有用的。
那么任何自己实现一个模态视图呢?
一种方式就是自己实现一个UIViewController,然后作为一个modalViewController视图显示。这种方式固然可以
,但是需要的工作量可就不少了,例如显示动画,动态布局等等。
这里我要说的另一种方法,就是实现这些系统模态视图的子视图,对系统视图进行定制,以满足我们自己的需求。可以完美的使用系统模态
视图已经提供的动画、自动布局等等行为。
二:系统模态视图的显示方式
系统模态视图的显示和上面提到到的自定义模态视图的显示方式有很大的差别。
UIActionSheet、UIAlertView、GKPeerPickerController、UIAPopover、GKPanel 都是UIView的子类,
如果直接在读取视图之上显示这些UIActionSheet等等的视图,是无法阻断事件的。因此系统自带的这些模态
视图先被添加到一个UIWindow的视图,再把给window视图作为application的keyWindow显示。也就是在显示
模态视图的时候,application的多window的。
三:移除系统模态
调用dismiss系列的方法移除模态视图
四:模态视图的实现基础
所有的模态视图都基于UIViewControll提供的两个方法:
– presentModalViewController:animated:
– dismissModalViewControllerAnimated:
UIActionSheet、UIAlertView的实现都是对这两个方法的实现和在实现。
五:向模态视图添加其他UIView的方式:
一:动态添加UIView
(1):通过[UIApplication sharedApplication].keyWindow 取得当前的makeKeyAndVisible window,该window的
大小是这个屏幕的大小,和该window包含的 UIActionSheet等视图不是一个级别。UIActionSheet 仅仅是该window的
一个子视图而已。
[[UIApplication sharedApplication].keyWindow addSubview:self.progressHUD];
(2):根据读取模态视图的window属性,取得当前的makeKeyAndVisible window
[self.actionSheet.window addSubview:self.progressHUD]
注意:以上两种方式一定要在模态视图显示出来之后再添加其他的UIview,否则添加的UIView可能无法显示。
二:静态添加UIView
把需要添加的UIView视图直接在模态视图的drawRect方法中添加就可以了。这些在显示模态视图时候,添加的
UIView也会被显示处理。
UIActionSheet 视图的自定义
// // UserDetailVoiceCustomActionSheet.h // BaiHe // // Created by xu on 12-12-15. // Copyright (c) 2012年 itotemstudio. All rights reserved. // #import <UIKit/UIKit.h> @protocol BHCustomActionSheetDelegate <NSObject> @optional - (void)actionSheet:(UIActionSheet *)actionSheet clickedOtherButtonAtIndex:(NSInteger)buttonIndex; - (void)actionSheetCancel:(UIActionSheet *)actionSheet; - (void)actionSheetDestructive:(UIActionSheet *)actionSheet; @end @interface BHCustomActionSheet : UIActionSheet { UIButton *_destructiveButton; id<BHCustomActionSheetDelegate> _customActionDelegate; } @property (nonatomic, retain) UIButton *destructiveButton; @property (nonatomic, assign) id<BHCustomActionSheetDelegate> customActionDelegate; @end
// // UserDetailVoiceCustomActionSheet.m // BaiHe // // Created by xu on 12-12-15. // Copyright (c) 2012年 itotemstudio. All rights reserved. // #import "BHCustomActionSheet.h" #import "UIImageExt.h" @interface BHCustomActionSheet () - (void)clickedOtherButton:(id)sender; - (void)clickCanncelButton; - (void)clickDestructiveButton; @end @implementation BHCustomActionSheet @synthesize destructiveButton = _destructiveButton; @synthesize customActionDelegate = _customActionDelegate; - (void)dealloc { _customActionDelegate = nil; RELEASE_SAFELY(_destructiveButton); [super dealloc]; } //去除背景色 - (void)drawRect:(CGRect)rect { UIImageView *bgView = [[[UIImageView alloc] initWithFrame:self.bounds] autorelease]; bgView.image = [[UIImage imageNamed:@"bg"] resizeUsingCapInsets:UIEdgeInsetsMake(180.f, 5.f, 4.f, 4.f)]; [self addSubview:bgView]; UILabel *titleLabel = nil; NSMutableArray *buttons = [NSMutableArray arrayWithCapacity:10]; for (UIView *view in self.subviews) { if ([view isKindOfClass:[UIControl class]]) { [self bringSubviewToFront:view]; [buttons addObject:view]; [view removeFromSuperview]; } if ([view isKindOfClass:[UILabel class]]) { titleLabel = (UILabel *)view; } } // if (titleLabel) { CGRect hilghtBgImageFrame = CGRectMake(0.0f, 0.0f, CGRectGetWidth(rect), CGRectGetMaxY(titleLabel.frame) == 0.f?60.f:CGRectGetMaxY(titleLabel.frame) + 5.f); UIImageView *hilghtBgImageView = [[[UIImageView alloc] initWithFrame:hilghtBgImageFrame] autorelease]; [self addSubview:hilghtBgImageView]; [self bringSubviewToFront:titleLabel]; hilghtBgImageView.image = [[UIImage imageNamed:@"bg-highlight"] resizeUsingCapInsets:UIEdgeInsetsMake(31.f, 5.f, 42.f, 4.f)]; // } NSMutableIndexSet *delSet = [NSMutableIndexSet indexSet]; if (self.destructiveButtonIndex >= 0) { NSString *destructiveButtonTitle = [self buttonTitleAtIndex:self.destructiveButtonIndex]; UIButton *customDestructiveBut = [UIButton buttonWithType:UIButtonTypeCustom]; self.destructiveButton = customDestructiveBut; [customDestructiveBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [customDestructiveBut setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateNormal]; customDestructiveBut.titleLabel.font = [UIFont boldSystemFontOfSize:18.f]; [customDestructiveBut setBackgroundImage:[[UIImage imageNamed:@"but_Destructive"] resizeUsingCapInsets:UIEdgeInsetsMake(15.f, 50., 20.f, 60.f)] forState:UIControlStateNormal]; [customDestructiveBut addTarget:self action:@selector(clickDestructiveButton) forControlEvents:UIControlEventTouchUpInside]; customDestructiveBut.frame = ((UIControl *)[buttons objectAtIndex:self.destructiveButtonIndex]).frame; [customDestructiveBut setTitle:destructiveButtonTitle forState:UIControlStateNormal]; [self addSubview:customDestructiveBut]; [delSet addIndex:self.destructiveButtonIndex]; } if (self.cancelButtonIndex >= 0) { NSString *cancelButtonTitle = [self buttonTitleAtIndex:self.cancelButtonIndex]; UIButton *customCancelBut = [UIButton buttonWithType:UIButtonTypeCustom]; [customCancelBut setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; [customCancelBut setTitleShadowColor:[UIColor grayColor] forState:UIControlStateNormal]; customCancelBut.titleLabel.font = [UIFont boldSystemFontOfSize:18.f]; [customCancelBut setBackgroundImage:[[UIImage imageNamed:@"but_Cancel"] resizeUsingCapInsets:UIEdgeInsetsMake(15.f, 50., 20.f, 60.f)] forState:UIControlStateNormal]; [customCancelBut addTarget:self action:@selector(clickCanncelButton) forControlEvents:UIControlEventTouchUpInside]; customCancelBut.frame = ((UIControl *)[buttons objectAtIndex:self.cancelButtonIndex]).frame; [customCancelBut setTitle:cancelButtonTitle forState:UIControlStateNormal]; [self addSubview:customCancelBut]; [delSet addIndex:self.cancelButtonIndex]; } [buttons removeObjectsAtIndexes:delSet]; int index = 0; for (UIControl *control in buttons) { NSString *otherButtonTitle = [self buttonTitleAtIndex:index]; UIButton *customOtherBut = [UIButton buttonWithType:UIButtonTypeCustom]; [customOtherBut setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; [customOtherBut setTitleShadowColor:[UIColor grayColor] forState:UIControlStateNormal]; customOtherBut.titleLabel.font = [UIFont boldSystemFontOfSize:18.f]; [customOtherBut setBackgroundImage:[[UIImage imageNamed:@"but_Cancel"] resizeUsingCapInsets:UIEdgeInsetsMake(15.f, 50., 20.f, 60.f)] forState:UIControlStateNormal]; customOtherBut.tag = index; [customOtherBut addTarget:self action:@selector(clickedOtherButton:) forControlEvents:UIControlEventTouchUpInside]; customOtherBut.frame = ((UIControl *)[buttons objectAtIndex:index]).frame; [customOtherBut setTitle:otherButtonTitle forState:UIControlStateNormal]; [self addSubview:customOtherBut]; index ++; } [buttons removeAllObjects]; } #pragma mark - Private Method - (void)clickedOtherButton:(id)sender { NSInteger index = ((UIControl *)sender).tag; if (self.customActionDelegate && [self.customActionDelegate respondsToSelector:@selector(actionSheet:clickedButtonAtIndex:)]) { [self.customActionDelegate actionSheet:self clickedOtherButtonAtIndex:index]; } [self clickCanncelButton]; } - (void)clickCanncelButton { if (self.customActionDelegate && [self.customActionDelegate respondsToSelector:@selector(actionSheetCancel:)]) { [self.customActionDelegate actionSheetCancel:self]; } [UIApplication sharedApplication].statusBarHidden = NO; } - (void)clickDestructiveButton { if (self.customActionDelegate && [self.customActionDelegate respondsToSelector:@selector(actionSheetDestructive:)]) { [self.customActionDelegate actionSheetDestructive:self]; } } @end
重新drawRect方法,可以去除UIActionSheet的默认样式,然后通过addSubView方法添加定制的视图。
发表评论
-
UIView 和 CALayer的那点事
2012-11-17 23:51 30628UIView 和 CALayer的那点事 (1 ... -
iOS Open Source : Popover API for iPhone
2012-01-20 15:02 1903http://iphonedevelopertips.com/ ... -
ios 任务、线程、定时器
2011-12-26 18:09 7977一:operations(任务) cocoa提供了三种 ... -
ios url缓存策略——NSURLCache、 NSURLRequest
2011-12-26 17:09 24312一:url 缓存策略 NSURLRequest ... -
ios NSInvocation简单使用
2011-12-22 16:39 6320在ios直接调用某个对象的消息是方法有两种: 一:perfo ... -
iphone 对Web Services的三种请求方式soap get post
2011-11-09 10:57 6374一:Using SO AP 1.1 POST / ... -
sdk3.2手势实例
2011-11-09 10:11 1704#import <UIKit/UIKit.h>@i ... -
关于iphone 利用hpple解析html的问题
2011-08-04 18:28 2171最近在用happe解析html中的图片。有个翻页操作,如果请 ... -
iphone hpple 解析html,xml
2011-07-19 16:21 2708使用Objective-C解析HTML或者XML,系统自带有两 ... -
激活 iPhone通过 GPRS 连接服务器功能的代码
2011-05-13 15:14 1611如果您的 iPhone 应用里含有连接服务器的功能,也许会遇到 ... -
address book api 图型
2011-04-28 15:51 1106最近要搞地址簿了,整理一下 -
[OmniGraffle]iPhone app原型制作工具
2011-04-06 17:35 3914在写程序之前,我们通常需要做一些mockup出来(不知道款爷有 ... -
自定义uislider 样式
2011-04-04 21:28 3795UIImage *stetchLeftTrack= [[UII ... -
iphone 下AsyncSocket网络库编程
2011-04-02 21:04 7589iphone的标准推荐CFNetwork ... -
进阶AlertView运用 - 登入设计
2011-04-01 17:52 2994说明:示范如何利用AlertView来制作系统登入的介面程式碼 ... -
iPad UIPopoverController弹出窗口的位置和坐标
2011-04-01 17:42 1959优化规则: TodoViewControlle ... -
iPhone系统自动化测试
2011-04-01 17:39 2575首先mac系统是必备的2 安装iPhone SD ... -
iphone上面编写具有root权限的程序
2011-04-01 17:31 6244正常途径下, 我们编写的程序发布在App store上, 使用 ... -
聊天。。。。。
2011-04-01 17:13 1054是得分手段 -
iOS开发基础:Modal View Controller的不同呈现方式
2011-04-01 16:40 2776ModalViewController可以有不同的呈现方式(m ...
相关推荐
IOS自定义UIActionSheet的例子,供大家学习
简单的自定义UIActionSheet
iOS 自定义弹出菜单 UIMenuBar ,UIMenuBar 是一个 iOS 自定义弹出菜单,用于替换内置的 UIActionSheet,支持...
自定义UIActionSheet控件功能,源码WCActionSheet,WCActionSheet 是一款自定义UIActionSheet控件 比UIActionSheet更加优雅 支持block语法,该案例控件希望可以帮到学习的朋友。 UIActionSheet is great... unless ...
iOS系统自带的UIActionSheet不方便修改内部button的字体大小,颜色,本人模仿实现了个小demo可以完成上述功能85
TOActionSheet TOActionSheet是一个iOS UI控件,提供了一个模式提示控件,类似于UIActionSheet 。 与UIActionSheet不同,它可以非常重地主题化,并通过为每个按钮使用块来避免委托模型。产品特点预定义的浅色和深色...
MMActionSheet 是一个简单的弹出选择框,使用纯swift编写,类似于微信(或支付宝)里面的`ActionSheet`控件。 源码地址(具体用法):https://github.com/MinMao-Hub/MMActionSheet 博客地址(使用方法以及具体参数...
该工具是自己封装的framework 其中自定义了UIKit的UIActivity和UIActionSheet 后续的自定义UI会持续更新 注意:framework分真机和模拟器 可以通过终端将两者合二为一 适用方法 直接将文件中的framework拖入工程 记得...
自定义的UIActionSheet案例,源码MTDActionSheet,MTDActionSheet是一款自定义的UIActionSheet 适用于iPad 使用Block作为回调 A customizable UIActionSheet replacement for the iPad
TBActionSheet是一个小型图书馆,使您可以替代苹果的不可自定义UIActionSheet ,具有美观和完全可定制的actionsheet,你可以在你的iOS应用使用。 默认样式为iOS9 / 10,您可以制作自己的样式。 请享用! 这是一些...
SQActionSheetView *acitionSheet = [[SQActionSheetView alloc]initWithTitle:@"" buttons:@[@"保存图片",@"分享图片",@"取消"] buttonClick:^(SQActionSheetView *sheetView, NSInteger buttonIndex) { ...
这个源码是自定义弹出视图UIActionSheet,源码LZWActionSheet,用了IOS8之后发现之前别人写得自定义UIActionSheet 不能正常显示了,于是我就自己写了一个,分享给大家 请用xcode 6.0.1 编译测试 记得使用的时候算好...
普通的列表对话框,使用简单,功能强大,可以自定义和强大,就像IOS中的UIActionSheet ##用 // Initialize an array of characters List< String> list = new ArrayList<> ( 3 ); list . add( " Send message ...
UIAlertController是iOS8推出的新概念,取代了之前的 UIAlertView和UIActionSheet(虽然现在仍可以使用,但是会有警告)。下面这篇文章主要给大家介绍了关于iOS中UIAlertController如何设置自定义标题与内容的相关...
UIAlertViewController,UIAlertView和UIActionSheet的可定制实现。 一体。 您可以自定义每个细节。 使AlertView成为您的梦想! :) 预习 默认警报视图 默认操作表 警报视图模糊 操作表模糊 自定义警报视图 自定义...
swift3.0 纯代码自定义ActionSheet,支持ios7 ,多功能选择器UIActionSheet,仿微信ActionSheet,还有其他样式改变,满足各种需求;
UIActionSheetDemo的简单使用,值得一提的是UIActionSheet的自定义在ios8上没法使用,使用xcode5就能看见效果了
这个是SHActionSheetBlocks功能源码,源码SHActionSheetBlocks 自定义UIActionSheet,SHActionSheetBlocks 是 UIActionSheet 的分类,提供了堵塞、自动移除特性,喜欢的朋友可以下载吧。 This pod is used by ...
在iOS8.0之前 我们可以使用UIAlertView 和 UIActionSheet 但是在9.0之后 官网默认用UIAlertController取代了这两个 在弹框上面选择省市区 按钮一是ActionSheet模式 按钮二是AlertView模式 欢迎各位童鞋学习使用 QQ...
作者dwalker39,源码DWNavMenu,DWNavMenu 是一个可以高度自定义的 UIActionSheet 风格的菜单,有着简单的导航和块处理。