Comments (14)
Sorry for the very delayed response, have been away on holiday.
Any changes to the constraint constant are not additive. So last method call to change the constraint constant wins. Since .offset() and other methods that modify the constraint constant can be called outside of makeConstraints block for animation etc
from masonry.
Let me know if you have any suggestions/solutions otherwise closing for now. thanks
from masonry.
@cloudkite I believe this is worth implementing, what do you think? It makes a lot of sense and should be pretty easy to do. I wanna try it :)
from masonry.
I think it should work like this:
MASConstraint *constraint = make.width.equalTo(200).with.offset(-40); // result = 160
...
constraint.offset = 100; // result = 300
On a side note, are we really supposed to be using methods like .offset()
outside of a constraint maker block?
from masonry.
@nickynick offset, insets, sizeOffset etc need to be called outside of a constraint maker block inorder to update constraints for animation etc.
I think having offset being additive would be very confusing, the developer would need to make sure they remember they have previously set an offset
Having a cumulative offset seems to me like it would cause alot of confusion
constraint.offset = 100; // result = 300
from masonry.
offset, insets, sizeOffset etc need to be called outside of a constraint maker block inorder to update constraints for animation etc.
That's right, what I wanted to say was that it feels much more intuitive to write constraint.offset = 100;
rather than constraint.offset(100);
. Anyway, having both of these available publicly is a bit confusing.
I think having offset being additive would be very confusing, the developer would need to make sure they remember they have previously set an offset
Why? You are thinking of offset as if it was an alias for "layout constant", but that's not really the case, IMO. A big cool thing about Masonry is that it allows you to write constraint code as sentences. So, to create a constraint, first you make it equal to something, and then you can specify an offset from that thing. It is absolutely expected when you relate to views and view attributes, and, to me, it's quite the same when you relate to values. First you specify a value, and then you can tweak it a bit by adding an offset.
from masonry.
And also, having to remember that you previously set an offset is not a problem, I think it should be like this:
MASConstraint *constraint = make.width.equalTo(200).with.offset(50); // width = 250
...
constraint.offset = -50; // width = 150
constraint.equalTo(300); // offset is reset, width = 300
constraint.offset = 100; // width = 400
from masonry.
However if you are relating the constraint to a view such
make.left.equalTo(otherView);
In this case you have no means of reseting the offset. As equalTo(200) can only be used if you are specifying constraints relative to the superview
from masonry.
Well, actually, I would expect that an equalTo()
called on existing constraint will always give me a fresh relation, overriding previous offsets. In this example, why would you want to preserve an offset of 30?
constraint = make.left.equalTo(otherView).with.offset(30);
// or constraint = make.left.equalTo(0).with.offset(30);
...
constraint.equalTo(100);
Perhaps I didn't quite understand your point, could you elaborate please?
from masonry.
Yeah you are right :) thought there were special assertions on equalTo as number but that's just on install time and doesn't apply outside of a maker block. What you are proposing makes sense, I'm just not entirely convinced there is enough benefit gained in changing offset to be cumulative to justify breaking existing projects?
from masonry.
I'm not sure either, to be honest :)
On one side, the current behaviour of example described by @ahti is pretty confusing. However, if we change it, I can see how this could be confusing as well:
constraint = make.left.equalTo(50);
constraint.offset = 100; // 50 + 100 :P
Maybe it makes sense to establish that using numbers for edge & position relations (make.left.equalTo(50)
) is essentially just a shorthand for superview relation + offset (make.left.equalTo(superview).with.offset(50)
)? This doesn't look confusing to me:
constraint = make.left.equalTo(100).with.offset(200); // you just get 200 here
constraint.offset = 300; // 300
from masonry.
In other words, this offset thing would only be cumulative for size constraints :)
from masonry.
Well, after all, perhaps it doesn't matter that much to introduce additional complex logic and potentially break someone's code for sake of implementing it :)
from masonry.
Maybe it's just worth to spawn a log message when overwriting a layout constant on a constraint which has not yet been installed? Like, "hey buddy, you might not get what you expect".
from masonry.
Related Issues (20)
- equalTo(@[@10,@30]),What is the meaning of using an array in parentheses of equalTo HOT 2
- tableViewHeaderView & textView HOT 1
- Snap
- Duplicate keys for NSLayoutAttributeBaseline and NSLayoutAttributeLastBaseline in NSLayoutConstraint+MASDebugAdditions.m HOT 1
- mas_
- instance method conflicts with same method from another category 警告
- Version 1.1.0 in Mapping to The Old Code, not The Newest Code ! HOT 3
- swift package!!!! HOT 1
- 'MASConstraint' with definition in module 'Masonry.MASConstraint' has different definitions in different modules; first difference is this method
- 缩小控件高度的动画 控件会错位平移
- Label 使用label.numberOfLines来切换行数,上下文会莫名多出来一部分空白 HOT 1
- the newest version is 1.1.0 , but the 1.1.0 is not newest code compare with the branch of master HOT 1
- 小数
- mas_equalTo crash!!!
- Is there a release plan for a new version?
- [self.installedView addConstraint:layoutConstraint]; 这句代码偶发崩溃
- ~/Library/Developer/Xcode/UserData/CodeSnippets HOT 1
- When the parent view does not add a constraint or set a frame, the child view sets a constraint with a warning.
- [MASConstraintMaker install] Crash occasionally online HOT 2
- 苹果新政策要求三方库添加隐私清单PrivacyManifest,能否支持一下? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from masonry.