1:contentSize、contentInset和contentOffset区别

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

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

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

2:IOS虚拟器安装其它Simulator

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

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

离线安装还有一个简单的办法就是将以前安装过的旧版本的Xcode如Xcode5.0.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, 200)];
[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:20]; //处理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];
}
}
}
}

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 = 35;
CGFloat toolbarW = self.view.width;
CGFloat toolbarY = self.view.height - toolbarH;
toolbar.frame = CGRectMake(0, 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(0, - 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 = 0; i<count; i++) {
UIButton *button = self.subviews[i];
CGFloat buttonX = buttonW * i;
button.frame = CGRectMake(buttonX, 0, buttonW, buttonH);
}
} @end

iOS开发基础知识碎片的更多相关文章

  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 ...

  10. IOS开发基础知识--碎片40

    1:Masonry快速查看报错小技巧 self.statusLabel = [UILabel new]; [self.contentView addSubview:self.statusLabel]; ...

随机推荐

  1. [Cache] C#操作缓存--CacheHelper缓存帮助类 [复制链接]

    using System;using System.Web;using System.Collections; namespace DotNet.Utilities{ public class Cac ...

  2. 在Java代码中使用iTextPDF生成PDF

    1. 生成PDF 载入字体 static { FontFactory.register("/fonts/msyh.ttf"); FontFactory.register(" ...

  3. IntelliJ IDEA运行tomcat项目编码错误, 及如何指定tomcat编码

    刚开始用IDEA, 在跑dubbo开发时, 发现一个很奇怪的问题, 远程调用服务端的方法时, 传入的中文参数会变成GBK编码. 经过好长时间的跟踪终于把问题定位到了IDEA里配置的Tomcat. 凡是 ...

  4. ASP.NET中获取当日,当周,当月,当年的日期

     ASP.NET中获取当日,当周,当月,当年的日期 在ASP.NET开发中,经常会碰到要获取当日,当周,当月,当年的日期. 以下将源码贴出来和大家分享. aspx中代码如下: <table ce ...

  5. C#字符串默认值

    using System; class MYTestX { class CT { } class CO { public CT ott; //默认是null public string strx;// ...

  6. Openwrt iptables分析

    这里将载有Openwrt的WR841N的路由表dump出来分析一下. 这个是dump出iptables的命令 root@OpenWrt:/etc/config# iptables-save 这里分为4 ...

  7. 如何优化 FineUI 控件库的性能,减少 80% 的数据上传量!

    在开始正文之前,请帮忙为当前排名前 10 唯一的 .Net 开源软件 FineUI 投一票: 投票地址: https://code.csdn.net/2013OSSurvey/gitop/codevo ...

  8. Windows数据类型

    WORD:16位无符号整形数据 DWORD:32字节无符号整型数据(DWORD32) DWORD64:64字节无符号整型数据 INT:32位有符号整型数据类型 INT_PTR:指向INT数据类型的指针 ...

  9. Theano2.1.18-基础知识之theano的扩展

    来自:http://deeplearning.net/software/theano/tutorial/extending_theano.html Extending Theano 该教程覆盖了如何使 ...

  10. ASP.NT运行原理和页面生命周期详解及其应用

    ASP.NT运行原理和页面生命周期详解及其应用 1. 下面是我画的一张关于asp.net运行原理和页面生命周期的一张详解图.如果你对具体不太了解,请参照博客园其他帖子.在这里我主要讲解它的实际应用.  ...