Coder Social home page Coder Social logo

hotpot's Introduction

👋 嗨,你好,我是晓峰。

我是一名 Web 前端开发,目前就职于 企业微信

我喜欢编程,也热衷基于 Swift 的 iOS 开发,最近一直在跑步。

这是我的开放生活日志 LifeLogs

hotpot's People

Contributors

r0uter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

hotpot's Issues

Subview's frame set after superview's frame not work properly

description:
I am trying to add a greenView as a subview of redView, and in viewDidLayoutSubviews:, when I set its frame after the redView already set its frame, I got nothing, to fix this, I must move the code before the redView frame code.
code I use:
[self.greenView frameLayout:^(HotpotFrameLayout *layout) {
layout.top.equalTo(self.redView.top).offset(20.f);
layout.left.equalTo(self.redView.left).offset(20.f);
layout.width.equalTo(20.f);
layout.height.equalTo(20.f);
}];
ps: greenView has already added to redView as a subview.

in subview view.top may not equal to self.top

top 、 bottom 等返回的是 minY、 maxY,在 subview 里,实际上应该返回 0 和 height,这个问题导致所有 subview 里的 view 无法使用类似下面的写法来和 subview 对齐:

.bottom.equalTo(self.top).offset(-40)
                    .centerX.equalTo(self.centerX)

因为坐标系统是偏移了的……

也就是说这个框架的相对布局仅能针对除顶层外同层 view 坐标系统,如果是在 subview 里,则需要用类似这样的写法:

.bottom.equalTo(self.height).offset(-40)
                    .centerX.equalTo(self.width/2)

解决办法:

在 readme 里加入相关说明…… XD

Add some support for Swift

Hotpot 太棒了,完美解决了我不喜欢 autolayout 但又嫌弃 frame 繁琐的问题……

不过我使用 Swift 开发,在使用 Hotpot 的时候遇到一个问题:

themeButton.frameLayout { (layout) in
            layout?.top.equalTo()(self.view.top)?.offset()(self.view.layoutMargins.top)
        }

这样的语法太难受了,于是我写了一个扩展来避免这些问题:

import Hotpot
extension HotpotFrameLayout {
    @discardableResult func equalTo(_ to:CGFloat) ->HotpotFrameLayout {
        return self.equalTo()(to)!
    }
    @discardableResult func offset(_ n:CGFloat) ->HotpotFrameLayout {
        return self.offset()(n)!
    }
}

虽然本质上还是 Objective-C 实现,但在 Swift 语法中使用起来也没什么明显的问题了呢。

优化后的语法:

themeButton.frameLayout { (layout) in
            layout?.top.equalTo(self.view.top).offset(self.view.layoutMargins.top)
        }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.