5. CocoaPods安装 Masonry 的一些心得

时间:2021-10-23 13:58:40

最近由于Xcode6之后需要做适配,但是之前全部是手写代码,学习了一下苹果推出的使用auto layout中得VFL(visual format language)可以实现代码自动布局,但是理解起来颇为费解,更别说要自己去写约束了,http://www.cocoachina.com/ios/20141209/10549.html (这个是相关的URL),可供大家学习,方法其实也是可行的,虽然比较麻烦。

想到自动适配这种大部头,github上肯定会有很好的第三方框架,于是一搜,还真发现了,叫做 Masonry,  https://github.com/Masonry/Masonry  ,这里还有一篇Masonry的中文介绍与使用 http://www.cocoachina.com/ios/20141219/10702.html (可供大家参考学习)。

使用masonry需要添加cocoaPods ,下面就进入正题(废话真多。。。)

The right way to enable CocoaPods in your Project is:

  1. Open Terminal and execute: $
    sudo gem install cocoapods
  2. Navigate to your Project folder (I assume in your case it's cd /Users/myName/Developer/SimpleWeather/SimpleWeather.xcodeproj).
  3. Setup Cocoapod pod setup
  4. Create the Podfile touch Podfile
  5. Open the Podfile open -e Podfile and insert your code for Podfile
  6. Finally install the Podfile pod install

If you follow this instructions everything should work. When opening your project make sure to open the .xworkspacefile.

For more information: http://cocoapods.org/


touch Podfile 这一步,利用vim打开Podfile文件编辑,加入你想要使用的类库,格式如下:

platform :ios
pod
'Reachability', '3.1.0'

platform:ios,
'6.0'
pod
'JSONKit','1.4'
pod
'AFNetworking', '~> 2.3.1'


常见的几个错误:

(1)

[!] Oh no, an error occurred.


It appears to have originated from your Podfile at line 1.


Search for existing github issues similar to yours:

https://github.com/CocoaPods/CocoaPods/search?q=%2FUsers%2Fhuaqiao%2FDesktop%2FUserCommand1%2FPodfile%3A1%3A+syntax+error%2C+unexpected+%27%3A%27%2C+expecting+end-of-input%0Aplatform+%3A+ios+%0A++++++++++%5E&type=Issues


If none exists, create a ticket, with the template displayed above, on:

https://github.com/CocoaPods/CocoaPods/issues/new


Be sure to first read the contributing guide for details on how to properly submit a ticket:

https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md

 解决方案:   You need reinstall cocoapods: so

sudo gem uninstall cocoapods
sudo gem install cocoapods
pod setup

(2)以下错误原因是路径错误,需要cd到你当前的项目路径中。

[!] Could not automatically select an Xcode project. Specify one in your Podfile like so:


    xcodeproj 'path/to/Project.xcodeproj'


(3)加入masonry如报错:

[!] The platform of the target `Pods` (iOS 4.3) is not compatible with `Masonry (0.6.0)` which has a minimum requirement of iOS 6.0 - OS X 10.7.

可以修改Podfile为: platform :ios, '6.0'


--转载请注明