1:contentSize、contentInset和contentOffset区别

contentSize 是scrollview中的一个属性,它代表scrollview中的可显示区域,假如有一个scrollview,它的frame为(,,,),而它的contentSize为(,).也就是说,这个scrollview整个内容的大小为(,),要通过上下滑动scrollview来查看(,)后的内容。

contentOffset 是scrollview当前显示区域顶点相对于frame顶点的偏移量,比如上个例子你拉到最下面,contentoffset就是( ,-),也就是y偏移了480

contentInset 是scrollview中contentView.frame.origin与scrollview.frame.origin的关系,比如contentView的frame为(,,,),那么contentInset则为(, ),它也可以设置上下左右

2:IOS虚拟器安装其它Simulator

下载后的dmg安装.这里主要以iOS7.0模拟器的离线安装为例进行说明,其他版本以此类推:

下载ios_7_0_simulator.dmg后打开dmg文件,可以看到安装包iPhoneSimulatorSDK7_0.pkg,使用安装器安装此安装包,默认会安装在所选分区的/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7..sdk目录下,完全退出Xcode后将刚才安装的iPhoneSimulator7..sdk整个目录复制或移动到/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs目录下即可,(Xcode.app右键可以"显示包内容“)重新启动Xcode一般就可以使用相应版本的模拟器进行开发和调试了。

离线安装还有一个简单的办法就是将以前安装过的旧版本的Xcode如Xcode5..2下面已经安装好了的iOS模拟器直接复制过来使用,目录位置都一样,都是在Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs里面。这样就不用再下载离线安装包了。

3:输入框中的inputaccessoryview和inputview

UITextFields和UITextView有一个inputAccessoryView的属性,当你想在键盘上展示一个自定义的view时,你就可以设置该属性。你设置的view就会自动和键盘keyboard一起显示了。需要注意的是,你所自定义的view既不应该处在其他的视图层里,也不应该成为其他视图的子视图。其实也就是说,你所自定义的view只需要赋给属性inputAccessoryView就可以了,不要再做其他多余的操作。

inputview则是键盘视图,当其为nil时则弹出的是系统默认的键盘;

实例一(给键盘上方设置一个工具条的方式):

- (void)createKeyboardTool
{
keyboardTool = [[UIToolbar alloc] initWithFrame: CGRectMake(kZero, kZero, kScreenW, 44.0f)];
NSMutableArray *myToolBarItems = [NSMutableArray array];   //创建键盘工具条上面的按钮,并设置点击事件
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(cancelAction)];
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:@selector(saveAction)];
UIBarButtonItem *saveBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(saveAction)]; [myToolBarItems addObject:cancelBtn];
[myToolBarItems addObject:space];
[myToolBarItems addObject:saveBtn];
keyboardTool.items = myToolBarItems;
} //inputAccessoryView:设置键盘顶部显示的工具条;inputView:自定义键盘
commentTextView = [[UITextView alloc]initWithFrame:CGRectMake(kZero, kZero, kScreenW, )];
[commentTextView becomeFirstResponder];
commentTextView.inputAccessoryView = keyboardTool; 实例二(修改键盘视图,进行切换自定义视图跟系统自带视图): /**
* 切换键盘
*/
- (void)switchKeyboard
{
// self.textView.inputView == nil : 使用的是系统自带的键盘
if (self.textView.inputView == nil) {
// 切换为自定义的表情键盘 emtionKeyboard为一个视图
self.textView.inputView = self.emotionKeyboard;
// 显示键盘按钮
self.toolbar.showKeyboardButton = YES;
} else {
// 切换为系统自带的键盘
self.textView.inputView = nil;
// 显示表情按钮
self.toolbar.showKeyboardButton = NO;
}
// 开始切换键盘 这个是为固定用的
self.switchingKeybaord = YES;
// 退出键盘
[self.textView endEditing:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// 弹出键盘,让其慢点实现
[self.textView becomeFirstResponder];
// 结束切换键盘
self.switchingKeybaord = NO;
});
} /**
* 键盘的frame发生改变时调用(显示、隐藏等)
*/
- (void)keyboardWillChangeFrame:(NSNotification *)notification
{
// 如果正在切换键盘,就不要执行后面的代码
if (self.switchingKeybaord) return; NSDictionary *userInfo = notification.userInfo;
// 动画的持续时间
double duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
// 键盘的frame
CGRect keyboardF = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; // 执行动画
[UIView animateWithDuration:duration animations:^{
// 工具条的Y值 == 键盘的Y值 - 工具条的高度
if (keyboardF.origin.y > self.view.height) { // 键盘的Y值已经远远超过了控制器view的高度
self.toolbar.y = self.view.height - self.toolbar.height;
} else {
self.toolbar.y = keyboardF.origin.y - self.toolbar.height;
}
}];
}

4:修改UISearchBar中关于cannel取消的文字

-(UISearchBar *)mySearchBar
{
if (_mySearchBar==nil) {
_mySearchBar=[[UISearchBar alloc]init];
_mySearchBar.showsCancelButton=YES;
_mySearchBar.delegate=self;
[_mySearchBar sizeToFit];
[_mySearchBar setPlaceholder:@"请输入"];
[_mySearchBar setY:]; //处理cannel的文字显示
for (id item in [_mySearchBar subviews]) {
for(id cc in [item subviews])
{
if ([cc isKindOfClass:[UIButton class]]) {
UIButton *btn=(UIButton *)cc;
[btn setTitle:@"取消" forState:UIControlStateNormal];
}
}
}
}
return _mySearchBar;
} 如果是获得瞧点才显示出取消可以在这个委托里面进行设置: /**
* @author wujunyang, 15-06-24 11:06:44
*
* @brief 修改cancel的显示文字 必先把showscancelButton设置为yes
* @param searchBar <#searchBar description#>
*/
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
searchBar.showsCancelButton=YES;
for (id item in [searchBar subviews]) {
for(id cc in [item subviews])
{
if ([cc isKindOfClass:[UIButton class]]) {
UIButton *btn=(UIButton *)cc;
[btn setTitle:@"取消" forState:UIControlStateNormal];
}
}
}
}

还有另外一种方式:

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
searchController.searchBar.showsCancelButton = YES;
UIButton *canceLBtn = [searchController.searchBar valueForKey:@"cancelButton"];
[canceLBtn setTitle:@"取消" forState:UIControlStateNormal];
[canceLBtn setTitleColor:[UIColor colorWithRed:14.0/255.0 green:180.0/255.0 blue:0.0/255.0 alpha:1.00] forState:UIControlStateNormal];
searchBar.showsCancelButton = YES;
return YES;
}

5:关于navigationController中增加控件时push跳转及跳回

在子页navigationController增加控件,回跳时它是没办法自个销除,所以要手动增加一个销除nav所增加的控件,否则子页的那个控件会被重叠显示在父页的nav上;如下一个实例:

在viewDidLoad里
//加载控件
[self.navigationController.view addSubview:self.mySearchBar]; (void)viewWillDisappear:(BOOL)animated {
//这句也可以写在回跳前
[self.mySearchBar removeFromSuperview];
[super viewWillDisappear:animated];
}

6:整个视图点击都对键盘进行收缩

- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *tapGr=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
//如果没有这句在view中的Button等可能无法触发ToucheUpInside事件
tapGr.cancelsTouchesInView=NO;
[self.view addGestureRecognizer:tapGr];
}
- (IBAction)BtnAction:(id)sender {
NSLog(@"%@",self.myTextField.text);
}
-(void)viewTapped:(UITapGestureRecognizer *)tapGr
{
[self.myTextField resignFirstResponder];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end

7:针对第三方插件为mrc,而工程为arc的调用

对第三方插件的.m文件进行设置,工程targets-build phases-compile sources 设置-fno-objc-arc

有些是双星如 PLTexture **previewTextures;
在arc下面则要修改成:PLTexture * __unsafe_unretained *previewTextures;

8:通知的方式实现键盘的收缩布局问题

/**
* 添加工具条
*/
- (void)setupToolbar
{
// 1.添加工具条
IWComposeToolbar *toolbar = [[IWComposeToolbar alloc] init];
toolbar.delegate = self;
CGFloat toolbarH = ;
CGFloat toolbarW = self.view.width;
CGFloat toolbarY = self.view.height - toolbarH;
toolbar.frame = CGRectMake(, toolbarY, toolbarW, toolbarH);
[self.view addSubview:toolbar];
self.toolbar = toolbar; // 2.监听键盘的弹出和隐藏
// 键盘的frame(位置)即将改变, 就会发出UIKeyboardWillChangeFrameNotification
// 键盘即将弹出, 就会发出UIKeyboardWillShowNotification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
// 键盘即将隐藏, 就会发出UIKeyboardWillHideNotification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
} #pragma mark - 键盘处理
/**
* 键盘即将隐藏
*/
- (void)keyboardWillHide:(NSNotification *)note
{
// 1.键盘弹出需要的时间
CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; // 2.动画
[UIView animateWithDuration:duration animations:^{
self.toolbar.transform = CGAffineTransformIdentity;
}];
} /**
* 键盘即将弹出
*/
- (void)keyboardWillShow:(NSNotification *)note
{
// 1.键盘弹出需要的时间
CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; // 2.动画
[UIView animateWithDuration:duration animations:^{
// 取出键盘高度
CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat keyboardH = keyboardF.size.height;
self.toolbar.transform = CGAffineTransformMakeTranslation(, - keyboardH);
}];
} //通知要销掉
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
} 注意:[self.textView resignFirstResponder];放弃瞧点
还有可以监听输入内容的变化: // 2.监听textView文字的改变
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChange) name:UITextViewTextDidChangeNotification object:textView];

9:封装一个uivew带有按键工具栏的实例

.h文件内容:

#import <UIKit/UIKit.h>

@class IWComposeToolbar;

typedef enum {
IWComposeToolbarButtonTypeCamera,
IWComposeToolbarButtonTypePicture,
IWComposeToolbarButtonTypeMention,
IWComposeToolbarButtonTypeTrend,
IWComposeToolbarButtonTypeEmotion
} IWComposeToolbarButtonType; @protocol IWComposeToolbarDelegate <NSObject>
@optional
- (void)composeToolbar:(IWComposeToolbar *)toolbar didClickButton:(IWComposeToolbarButtonType)butonType;
@end @interface IWComposeToolbar : UIView
@property (weak, nonatomic) id<IWComposeToolbarDelegate> delegate;
@end .m文件内容: #import "IWComposeToolbar.h" @implementation IWComposeToolbar - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// 1.设置背景
self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithName:@"compose_toolbar_background"]]; // 2.添加按钮
[self addButtonWithIcon:@"compose_camerabutton_background" highIcon:@"compose_camerabutton_background_highlighted" tag:IWComposeToolbarButtonTypeCamera];
[self addButtonWithIcon:@"compose_toolbar_picture" highIcon:@"compose_toolbar_picture_highlighted" tag:IWComposeToolbarButtonTypePicture];
[self addButtonWithIcon:@"compose_mentionbutton_background" highIcon:@"compose_mentionbutton_background_highlighted" tag:IWComposeToolbarButtonTypeMention];
[self addButtonWithIcon:@"compose_trendbutton_background" highIcon:@"compose_trendbutton_background_highlighted" tag:IWComposeToolbarButtonTypeTrend];
[self addButtonWithIcon:@"compose_emoticonbutton_background" highIcon:@"compose_emoticonbutton_background_highlighted" tag:IWComposeToolbarButtonTypeEmotion];
}
return self;
} - (void)addButtonWithIcon:(NSString *)icon highIcon:(NSString *)highIcon tag:(IWComposeToolbarButtonType)tag
{
UIButton *button = [[UIButton alloc] init];
button.tag = tag;
[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[button setImage:[UIImage imageWithName:icon] forState:UIControlStateNormal];
[button setImage:[UIImage imageWithName:highIcon] forState:UIControlStateHighlighted];
[self addSubview:button];
} /**
* 监听按钮点击
*/
- (void)buttonClick:(UIButton *)button
{
if ([self.delegate respondsToSelector:@selector(composeToolbar:didClickButton:)]) {
[self.delegate composeToolbar:self didClickButton:button.tag];
}
} - (void)layoutSubviews
{
[super layoutSubviews]; int count = self.subviews.count;
CGFloat buttonW = self.width / count;
CGFloat buttonH = self.height;
for (int i = ; i<count; i++) {
UIButton *button = self.subviews[i];
CGFloat buttonX = buttonW * i;
button.frame = CGRectMake(buttonX, , buttonW, buttonH);
}
} @end

IOS开发基础知识--碎片17的更多相关文章

  1. IOS开发基础知识碎片-导航

    1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...

  2. IOS开发基础知识--碎片33

    1:AFNetworking状态栏网络请求效果 直接在AppDelegate里面didFinishLaunchingWithOptions进行设置 [[AFNetworkActivityIndicat ...

  3. IOS开发基础知识--碎片42

    1:报thread 1:exc_bad_access(code=1,address=0x70********) 闪退 这种错误通常是内存管理的问题,一般是访问了已经释放的对象导致的,可以开启僵尸对象( ...

  4. IOS开发基础知识--碎片50

      1:Masonry 2个或2个以上的控件等间隔排序 /** * 多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值 * * @param axisType 轴线方向 * @param fi ...

  5. IOS开发基础知识--碎片3

    十二:判断设备 //设备名称 return [UIDevice currentDevice].name; //设备型号,只可得到是何设备,无法得到是第几代设备 return [UIDevice cur ...

  6. IOS开发基础知识--碎片11

    1:AFNetwork判断网络状态 #import “AFNetworkActivityIndicatorManager.h" - (BOOL)application:(UIApplicat ...

  7. IOS开发基础知识--碎片14

    1:ZIP文件压缩跟解压,使用ZipArchive 创建/添加一个zip包 ZipArchive* zipFile = [[ZipArchive alloc] init]; //次数得zipfilen ...

  8. IOS开发基础知识--碎片16

    1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOO ...

  9. IOS开发基础知识--碎片19

    1:键盘事件顺序 UIKeyboardWillShowNotification // 键盘显示之前 UIKeyboardDidShowNotification // 键盘显示完成后 UIKeyboar ...

随机推荐

  1. 前端学PHP之面向对象系列第四篇——关键字

    × 目录 [1]public [2]protected [3]private[4]final[5]static[6]const[7]this[8]self[9]parent 前面的话 php实现面向对 ...

  2. Java基础之类Class使用

    大家都知道Java是一门面向对象编程语言,在Java世界里,万事万物皆对象,那个Java中怎么表示对象呢?Class 我们知道Java中的对象都是Object类的子类,那么今天我们就一起来研究一下Ja ...

  3. Struts.xml中Action的method与路径的三种匹配方法

    原文  http://blog.csdn.net/woshixuye/article/details/7734482 首先我们有一个Action——UserAction public class Us ...

  4. The network bridge on device VMnet0 is not running

    The network bridge on device VMnet0 is not running. The virtual machine will not be able to communic ...

  5. 给Easyui combobox设定默认值

          今天做到那个北理工二期的项目,里面刚好有几个dialog需要弄一个默认值,一般是选择启用与否,但是,为了方便用户,最好有一个默认值,所以,增加一个默认值的属性.代码入下: JS代码:   ...

  6. Angular 结合RequireJs实现模块化开发

    angular的指令是模块化很好的一个体现,下面我将只使用指令(不用控制器),结合requirejs,实现模块化开发. 模块化关系图:

  7. EasyUI+MVC+EF简单用户管理Demo(问题及解决)

    写在前面 iframe-src EntityFramework版本 connectionStrings View.Action.页面跳转 EasyUI中DataGrid绑定 新增.修改和删除数据 效果 ...

  8. ZOJ Problem Set - 1109 Language of FatMouse

    这道题目最让人头疼的就是该题的input怎么结束,因为它要求输入一个空行的时候则一串字符串输入结束,这就不得不让人绕个弯来解决这个问题. (注:本人习惯于使用C中的字符串操作,但是用到map要求使用s ...

  9. MySQL入门03-MySQL配置安全性、易用性

    一.设定管理员用户和密码 二.处理test库权限隐患 三.自定义脚本提升易用性 中间定义文件 启动MySQL服务 关闭MySQL服务 快捷登录MySQL 四.设置开机自动启动MySQL服务 Refer ...

  10. Oracle数据库的SQL分页模板

    在系统开发过程中,需要对数据进行查询,大部分情况下从数据库中查询的数据量比较大,在系统页面无法全部显示,而且查询全部的数据会影响系统的反应速度,需要对所查询的数据进行分页的查询操作,以此减轻系统的压力 ...