学习笔记:
2016.4.29
1.安装cocoa pods,遇到的问题Could not find a valid gem ‘cocoapods'
这是因为ruby的软件源rubygems.org因为使用亚马逊的云服务,被我天朝屏蔽了,需要更新一下ruby的源,过程如下:
$ gem sources -l (查看当前ruby的源)
$ gem sources --remove https://rubygems.org/
$ gem sources -a https://ruby.taobao.org/
$ gem sources -l
如果gem太老,可以尝试用如下命令升级gem
$ sudo gem update --system
升级成功后会提示: RubyGems system software updated
解决上面的问题之后,运行以下:
sudo gem install cocoapods
pod setup
2016.5.1
1.编译时提醒App Transport Security has blocked a cleartext HTTP
原因:在iOS9 beta中,苹果将原http协议改成了https协议,使用 TLS1.2 SSL加密请求数据。
解决方法:
在info.plist 加入key
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
2.将其它工程的pods导入到新的工程
a.将podfile,podfile.lock拷贝到新工程下,然后运行pod install
b.ld: library not found for -lXXXXX 编译问题
解决方法:The Pods Xcode project now sets the ONLY_ACTIVE_ARCH build setting to YES in the Debug configuration. You will have to set the same on your project/target
2016.5.2
1.ios开发中iphone模拟器数据库存放的位置
a.有时MAC系统把资源库中的有些文件夹给隐藏了,首先要保证资源库中的文件夹是不被隐藏的 chflags nohidden ~/library/ ,若要隐藏:chflags hidden ~/library
b.查找目录/Users/user/Library/Developer/CoreSimulator/Devices/D126B5FE-9DDA-4185-A551-6D29562143A4/data/Containers/Data/Application; “D126B5FE-9DDA-4185-A551-6D29562143A4” 需要替换
2.查询网络接口一般采用GET方法
3.报错Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: URLString’
解决方法:需要处理urlString的编码
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
2016.5.9
1.设置button 的title左对齐
clearButton.titleLabel.textAlignment = NSTextAlignmentLeft;无效
[clearButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];有效
2.设置tabbar的图片默认颜色,不是灰灰的
- (void)awakeFromNib {
[super awakeFromNib];
for (UITabBarItem *item in self.tabBar.items) {
item.image = [item.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
}
3.设置图片为系统默认颜色
[[UIImage imageNamed:@"worldwide"]imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
4.查询pod里面第三方类库的版本
pod search AFNetworking
2016.5.10
1.UISlide 设置滑块图片,如果图片过小,则应该注意
- (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value {
rect.origin.x = rect.origin.x - 2 ;
rect.size.width = rect.size.width + 4;
return CGRectInset ([super thumbRectForBounds:bounds trackRect:rect value:value], 2 , 2);
} 这些值也应相应变小
2.从[[UIStoryboard storyboardWithName:@"MusicList" bundle:[NSBundle mainBundle]] instantiateInitialViewController];可能会读出UINavigationController,要想读取Viewcontroller,则应该[[UIStoryboard storyboardWithName:@"MusicList" bundle:[NSBundle mainBundle]]instantiateViewControllerWithIdentifier:@"musicList”];
2016.5.19
1.AFNetworking 错误 Request failed: unacceptable content-type: text/plain
self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", @"text/json", @"text/javascript",@"text/plain", nil];
2016.6.14
1.pod报错 The dependency `SDWebImage` is not used in any concrete target
解决办法:修改为target 'FreeMusicPlayer’ do
pod 'SDWebImage'
end
2016.7.13
如果不设置self.navigationController.navigationBar.translucent = NO;导航栏实际的颜色值会比设置值浅
2016.7.26
google driver 下载文件时出现错误Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup
主要是权限问题,此处设置的权限是kGTLAuthScopeDriveMetadataReadonly 只读权限,应该调整为其他,比如kGTLAuthScopeDrive
解决此问题的思路:先是在github上面搜索google driver,但是没有有用资料,然后考虑在官网上面查,官网上面给出了注意事项,要设置权限;然后以相应权限关键词在代码里面搜索,找到了码头,重新进行了设置;同时,可以以相应关键词在github里面搜索代码,这样出来了很多相关的资料。
2016.8.1
1.IOS获取剩余设备空间代码
#include <sys/param.h>
#include <sys/mount.h>
+ (NSString *) freeDiskSpaceInBytes{
struct statfs but;
long long freespace = -1;
if(statfs("/var", &buf) >= 0){
freespace = (long long)(buf.f_bsize * buf.f_bfree);
}
return [NSString stringWithFormat:@"手机剩余存储空间为:%qi MB" ,freespace/1024/1024];
}
2.改变app默认系统颜色
[[UIView appearance] setTintColor:[UIColor redColor]];
大部分有效,小部分需要特殊处理
比如UIAlertSheetAction的cancelButton颜色
需要通过设置[cancelAction setValue:[UIColor colorWithHexRGB:kAppColor] forKey:@"_titleTextColor"];
2016.11.16
1.安装brew
安装命令如下:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
当brew安装成功后,就可以随意安装自己想要的软件了,例如wget,命令如下:
sudo brew install wget
卸载的话,命令如下:
sudo brew uninstall wget
查看安装软件的话,命令如下:
sudo brew search /apache*/
注意/apache*/是使用的正则表达式,用/分割。
2. 在mac os下使用ffmpeg
在mac os下使用ffmpeg比较简单,可以直接使用命令行来操作。首先安装ffmpeg,这里默认系统已经安装好brew,只需要在终端上输入:
brew install ffmpeg
等待安装结束即可。
安装结束后,尝试以下命令:
ffmpeg -i input.mp4 output.avi
如果能顺利转换,表明安装成功
2016.12.26
a.创建python Flask环境 (在MAC里,python已经默认安装了)
1.安装vurtualenv : $ sudo easy_install virtualenv
2.新建virtualenv工程 :$ virtualenv myenvu (myenvu为工程名,先转到放置地址,然后再执行此命令)
3.激活virtualenv环境 :$ . myenvu/bin/activate
4.安装flask :$ pip install Flask
b.app 私有api分析
每次要运行 flask需要先激活cd /Users/user/Documents/myproject 然后. myenvu/bin/activate
运行工具 cd /Users/user/Downloads/iOS-private-api-checker-master 然后 python run_web.py
2017.3.6
1.生成图标,进入控制台,cd到文件路径,运行 sh xxx.sh,xxx为文件名
2.xib UIView 如何自定义frame,选中该xib文件,右边菜单栏选择show the Attributes(第四个图标),设置size为freeform,其他为none即可
3.xib UIView 上面的按键无法响应事件 ,很有可能是view frame设置的问题;xib UIView的frame有时会受到autoResizingMask的影响,需要在xib页面将其去掉选中
2017.4.5
1.横竖屏适配,转屏没有动画效果,需要将main interface和launch screen file设置为nil;
2017.4.6
1.通过代码为xib或sb中view增加约束时,尽量避免在 viewDi dLoad中执行,最好放在updateViewConstraints[UIViewController]或者updateConstraints[UIView]中 ,记得调用[super updateViewConstraints]或者[super updateConstraints];
在这里为你的view添加约束,请确保该view的translatesAutoresizingMaskIntoConstraints属性已设置为NO