Utopia
ID:
278
Utopia
UtopiaCHN
iOS developer
2015-11-10
  • Xcode 调试技巧之 OC 篇 2015-11-11 00:44:23 +0800

    学习

  • 使用 Masonry 配置好约束,再给每个 label 设置好内容(内容确定已经设置),为什么拿到的 label 的宽度是 0 2015-11-11 00:39:50 +0800

    @dugege 不行额,谢谢了,我再想想别的办法。

  • Masonry 框架从官方 GitHub 下载的 example 怎么运行 2015-11-11 00:36:58 +0800

    @iBcker 谢谢,都没遇到过好几个工程的情况。。

  • Masonry 框架从官方 GitHub 下载的 example 怎么运行 2015-11-10 11:16:37 +0800

    @iBcker 谢谢,我运行pod install 已经成功了,但是Xcode里同时有好几个project,我不知道怎么运行其中的 example project,所有的文件都编译成功就是没有弹出模拟器,单独进入Example文件下运行又编译错误,里面都没有xcworkspace类型的文件,我在 Example 文件夹下再创建一个 podfile 文件,写入 pod 'Masonry',但是pod install时候又错误了,好像是重复建立了。

  • 使用 Masonry 配置好约束,再给每个 label 设置好内容(内容确定已经设置),为什么拿到的 label 的宽度是 0 2015-11-10 11:06:46 +0800

    @dugege 嗯,还是不行。 我想实现简书滑动选择类别的功能,下图绿线部分。

    file

    但是我发现如果两个label并列显示在同一个view里,左边的label左对齐父视图,右边的label右对齐父视图,那么左边的label总是比右边的label宽。就像下图中的两个label:

    file

    这是实现的代码:

    _label1 = [UILabel new];
    _label1.backgroundColor = [UIColor yellowColor];
    _label1.text = @"label,";
    
    _label2 = [UILabel new];
    _label2.backgroundColor = [UIColor greenColor];
    _label2.text = @"label,";
    
    [_contentView1 addSubview:_label1];
    [_contentView1 addSubview:_label2];
    
    [_label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_contentView1.mas_top).with.offset(5);
        make.left.equalTo(_contentView1.mas_left).with.offset(2);
        make.height.equalTo(@40);
    }];
    
    [_label2 mas_makeConstraints:^(MASConstraintMaker *make) {
    
        make.left.equalTo(_label1.mas_right).with.offset(2);
        make.top.equalTo(_contentView1.mas_top).with.offset(5);
        make.right.equalTo(_contentView1.mas_right).with.offset(-2);
        make.height.equalTo(@40);
    }];
    
    [_label1 setContentHuggingPriority:UILayoutPriorityRequired
                               forAxis:UILayoutConstraintAxisHorizontal];
    
    [_label1 setContentCompressionResistancePriority:UILayoutPriorityRequired
                                             forAxis:UILayoutConstraintAxisHorizontal];
    
    [_label2 setContentHuggingPriority:UILayoutPriorityRequired
                               forAxis:UILayoutConstraintAxisHorizontal];
    
    [_label2 setContentCompressionResistancePriority:UILayoutPriorityRequired
                                             forAxis:UILayoutConstraintAxisHorizontal];
    

    所以为了解决这个问题我就让右边的 label 不要右对齐父视图,但是这样两个 label 就可能填不满父视图,父视图的右边可能空出一截,也有可能出现父视图不够大的情况,所以我就想在设置好 labe l后重新计算父视图的宽度,但是结果拿不到 label 的宽度。

    可能是 ContentHugging 和 ContentCompression 设置的不对。我对 Masonry 还不熟悉,想下载 demo 学习,结果又运行不了。好郁闷,我现在运行 pod instal 已经成功了,但是 xcode 里同时有好几个工程,example 是其中一个工程,所以的工程都编译成功了,但是我不知道怎么让 example 工程运行。单独进入 Example 文件夹运行工程又编译错误, Example 文件下面没有 .xcworkspace 类型的文件,只有xcodeproj文件,但是又用到cocoapods 。无解了。。。

  • Swift 中国社区成立 2015-11-10 09:37:22 +0800

    @iBcker 效率好赞

  • 使用 UICollectionView 实现的一个卡片动画 2015-11-10 09:26:41 +0800

    很好

  • Swift 中国社区成立 2015-11-10 09:22:30 +0800

    网页的左上角[Swift 中国]是不是应该设置点击回到首页,老是习惯性地点击。

  • Masonry 框架从官方 GitHub 下载的 example 怎么运行 2015-11-10 08:51:12 +0800

    @dugege 哦哦,我 pod install的时候报错了,Google下,好像是要把CocoaPods 的 installer.project 改变成 installer.pods_project,但是不知道怎么配置。下面是报错的信息:

    Utopia:Masonry utopia$ pod install
    Updating local specs repositories
    Analyzing dependencies
    Fetching podspec for `Masonry` from `./`
    Downloading dependencies
    Using Expecta (1.0.0)
    Installing Masonry 0.6.3 (was 0.6.1)
    Generating Pods project
    [!] An error occurred while processing the post-install hook of the Podfile.
    
    undefined method `project' for #<Pod::Installer:0x007f876a1cc048>
    
    /Users/utopia/Documents/iOS/Test/Masonry/Podfile:28:in `block (2 levels) in from_ruby'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-core-0.39.0/lib/cocoapods-core/podfile.rb:170:in `call'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-core-0.39.0/lib/cocoapods-core/podfile.rb:170:in `post_install!'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/installer.rb:806:in `run_podfile_post_install_hook'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/installer.rb:794:in `block in             /run_podfile_post_install_hooks'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/user_interface.rb:140:in `message'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/installer.rb:793:in `run_podfile_post_install_hooks'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/installer.rb:158:in `block in generate_pods_project'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/user_interface.rb:59:in `section'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/installer.rb:153:in `generate_pods_project'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/installer.rb:111:in `install!'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/command/project.rb:71:in `run_install_with_update'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/command/project.rb:101:in `run'
    /usr/local/lib/ruby/gems/2.2.0/gems/claide-0.9.1/lib/claide/command.rb:312:in `run'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/command.rb:47:in `run'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/bin/pod:44:in `<top (required)>'
    /usr/local/bin/pod:23:in `load'
    /usr/local/bin/pod:23:in `<main>' 
    
  • Masonry 框架从官方 GitHub 下载的 example 怎么运行 2015-11-10 08:46:55 +0800

    @iBcker 我运行pod install 的时候报错了,Google下,好像是要把CocoaPods 的 installer.project 改变成 installer.pods_project,但是不知道怎么配置。下面是报错的信息:

    Utopia:Masonry utopia$ pod install
    Updating local specs repositories
    Analyzing dependencies
    Fetching podspec for `Masonry` from `./`
    Downloading dependencies
    Using Expecta (1.0.0)
    Installing Masonry 0.6.3 (was 0.6.1)
    Generating Pods project
    [!] An error occurred while processing the post-install hook of the Podfile.
    
    undefined method `project' for #<Pod::Installer:0x007f876a1cc048>
    
    /Users/utopia/Documents/iOS/Test/Masonry/Podfile:28:in `block (2 levels) in from_ruby'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-core-0.39.0/lib/cocoapods-core/podfile.rb:170:in `call'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-core-0.39.0/lib/cocoapods-core/podfile.rb:170:in `post_install!'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/installer.rb:806:in `run_podfile_post_install_hook'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/installer.rb:794:in `block in         /run_podfile_post_install_hooks'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/user_interface.rb:140:in `message'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/installer.rb:793:in `run_podfile_post_install_hooks'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/installer.rb:158:in `block in generate_pods_project'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/user_interface.rb:59:in `section'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/installer.rb:153:in `generate_pods_project'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/installer.rb:111:in `install!'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/command/project.rb:71:in `run_install_with_update'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/command/project.rb:101:in `run'
    /usr/local/lib/ruby/gems/2.2.0/gems/claide-0.9.1/lib/claide/command.rb:312:in `run'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/lib/cocoapods/command.rb:47:in `run'
    /usr/local/lib/ruby/gems/2.2.0/gems/cocoapods-0.39.0/bin/pod:44:in `<top (required)>'
    /usr/local/bin/pod:23:in `load'
    /usr/local/bin/pod:23:in `<main>'
    
  • Masonry 框架从官方 GitHub 下载的 example 怎么运行 2015-11-10 08:41:02 +0800

    @dugege 我把它们都设置成none,还是不行额

  • Masonry 框架从官方 GitHub 下载的 example 怎么运行 2015-11-10 08:39:14 +0800

    @iBcker 我有安装cocoapods

  • Masonry 框架从官方 GitHub 下载的 example 怎么运行 2015-11-10 08:21:53 +0800

    @dugege 我看了下已经加载了

    file

  • Masonry 框架从官方 GitHub 下载的 example 怎么运行 2015-11-10 08:17:03 +0800

    @dugege 还有怎么把 CocoaPods 的 installer.project 改变成 installer.pods_project呢

  • Masonry 框架从官方 GitHub 下载的 example 怎么运行 2015-11-10 08:15:23 +0800

    @dugege configurations的配置文件怎么加载呢

  • Masonry 框架从官方 GitHub 下载的 example 怎么运行 2015-11-10 07:01:28 +0800

    @dugege 没有啊,我想学习 Masonry 框架网上的教程又不全面,想要下载官方的 example 学习,但是又不回运行。。。可能是 CocoaPods 的问题