NSLayoutConstraint to hidden objects still overrides alternate constraint - ios6

I am just for the first time trying to use Autolayout in a nib. It would seem my case is textbook situation where the NSLayoutConstraints would be the perfect solution.
I have a UITableviewCell with UILabel and an image beside it. The image changes according to the properties of the underlaying data, it can change size and sometimes be hidden. My intent is for the label to keep a set distance from the image and to span the entire cell when the image is hidden.
I set constraints on the label accordingly:
One constraint with trailing edge a set distance from the leading edge of the image, high priority but not required.
One constraint with trailing edge a set distance from the superview edge, with much lower priority.
Appropriate left and top restraints, no restraint for the width of the label.
The label remains shortened by the first constraint, even when the image is hidden. Is this expected behavior? I would ordinarily calculate and change the width of the label at runtime but this seems exactly the sort of situation that NSLayoutConstraints was meant for.
How do I get it to ignore the restraint to the image when the image is not visible?

From the class reference of NSLayoutConstraint, changing the priority of a constraint is not allowed once the constraint is laid. And a higher priority constraint will always override the lower ones.
The constraint can be removed and added back. If the constraint is put through storyboard or IB, you can make an IBOutlet of NSLayoutConstraint and connect it.
If you use the Xcode feature that auto-generates the line of code for the IBOutlet, it will declare the IBOutlet as weak. You need to change it to strong if you are going to add back the constraint some time in future after you remove it. This is to avoid the constraint being released after it is removed.
Then you can remove the first constraint if the image is hidden, and the second constraint will take place.
[self.view removeConstraint:self.firstConstraint];
You might need to call the layoutIfNeeded after removing the constraint.

With ios 8, you can activate/deactivate a constraint (https://developer.apple.com/library/ios/releasenotes/General/iOS80APIDiffs/frameworks/UIKit.html):
I would create 2 constraints, one with lower priority, and deactivate the higher priority one when hiding the view, and reactivating it when the view is visible again:
[self.firstConstraint setActive:NO];

Related

How do I rotate a SCNNode to look at another node, whilst keeping its roll and pitch level with the camera?

I am using ARKit to direct people to a position in the physical world using an arrow attached to the camera node. Applying a lookAtConstraint to the arrow with a target of a node in the location I want almost does what I need. However, I need to stop the arrow from rolling left and right and pitching up and down. Example of UI
Have you tried setting isGimbalLockEnabled to true to constrain the roll rotation? In the documentation Apple mentions: "For example, when constraining a camera to follow a moving object, setting this property to true ensures that the horizon remains level from the camera’s point of view."
If that still isn't what you're looking for, you may need to write a custom constraint using the class function SCNTransformConstraint.orientationConstraint. You could write the constraint as a secondary constraint that basically restricts rotations on the X and Z axes, or you could write your own look-at constraint with more restrictions (in which case I'd recommend looking at the simd.look(at:) function and then restricting the orientation axes from there).
This should get you most of the way there, or I can add some code in later if it doesn't seem to be working. Good luck!

Why are panelGridLayouts overlapping?

I am building a form which contains two forms adjacent to each other. Hence I used PanelGridLayout and placed two panelFormLayout in each 50% width gridCell of first gridRow of a PanelGridLayout. This works perfect with respect to alignment but in a smaller resolution both the gridcell's are overlapping and the fields of left form are overlapping with the labels of the right form.
How can I resolve this issue?
Any ideas on which layouts I can use?
What would you expect it to do in such a case where there is basically not enough space to show the fields in one of the sides?
ADF won't automatically shrink or eliminate fields in such a case.
Acc to the Geometry Management of <af:gridCell>
Beware that if you attempt to use width="auto", halign="center", halign="end" in conjunction with cell content that uses unstable, percentage-based widths, you may experience different results in different browsers. If you wish to use these settings, be sure to constraint the width of that cell content.
Possible Workaround
instead of halign="end" change it to halign="stretch"
source : https://docs.oracle.com/cd/E35521_01/apirefs.111230/e17491/tagdoc/af_gridCell.html

IOS6 Constraints using Autolayout

I have an app that can be rotated, so I need to deal with portrait and landscape orientations. Additionally, users will be allowed to use pinch gestures to change the scale of views. Here is the basic hierarchy of the views.
mainView is a subview of self.view (from the context of the main view controller). It is a UIImageView, although the image part of it is relatively unimportant. In any case, this is the view within which the rest of the views in this discussion are placed as subviews.
The first is what I call the board. It is the view on which items are assembled by the user. These items are themselves image views.
Additionally, there are what I call palettes. These are simply views that can be resized and scaled by the user. Additionally, the image views just mentioned can be dragged from one palette to another or to the board. The palettes can be thought of as work space for the user. When they are finished their work, they place their assembly onto the board.
So far, I've been working with the app where the board is part of autolayout but the palettes are created programatically as needed. This is good because when the user rotates the device, autolayout automatically places the board appropriately. At least it did until I wanted to add pinch scaling to it.
Autolayout has the following constraints set to it in interface builder:
Leading, top, trailing, and bottom all set to superview default.
When the user scales the view, the result is that it sort of sticks to the upper-left corner of the screen. I'd rather have it retain the center.
I tried changing this programmatically by adding the following code to the pinch gesture recognizer for this view:
if (self.pinchView.tag == TAGBOARD) {
[NSLayoutConstraint constraintWithItem:self.pinchView
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.mainView
attribute:NSLayoutAttributeCenterX
multiplier:1.0
constant:0];
}
but this seemed to do nothing. I'm guessing it's because it conflicts with the IB constraints. Is there something else I can do to make this work with autolayout? Or should I just do it all programmatically like I do with the other views?
In this code example, self.pinchView is the view on which the pinch gesture is applied to. For the sake of this discussion, it is what I've called the board. The self.mainView view is its superview.
The part we're not seeing in the code is something like
[self.pinchView addConstraint:yourNewConstraint];
I can see where you create the constraint, but not add it to the view. If you want your constraint to win you'll need to remove the other views or make sure the new constraint has a higher priority.
If your view should be centered, try adjusting the constraints in the storyboard to pin the width and height to the default and then aligning horizontally in the center. That should satisfy autolayout and replicate what you're trying to add, then in your pinch recognizer you can change the constant of the width and height. Be sure to drag your width and height constraints into your controller to create an outlet so that you can adjust them during the pinch gesture.

Keeping a UILabel centered with changing contents and AutoLayout

I have 2 views. A MapKitView and a UILabel. Auto Layout is on.
I want the MKView to take up the whole screen (this seems to work fine) and the UILabel to remain the auto distance from the bottom of the screen but centered horizontally. The UILabel contents are changed programatically and afterwards I am calling sizeToFit.
After calling sizeToFit on the UILabel then it is no longer centered - the width seems to be adjusted only from the right hand side (trailing edge) keeping the left hand side in a constant position.
My understanding is that I should be able to achieve what I want only by setting the right constraints in IB?
The constraints I have applied to the label are:
Height Equals: 32
Width Equals: 166
Bottom Space to: Superview Equals: Default
Align Center X to: Map View
Only the last one, "Align Center X" is a user constraint - the rest being IB supplied.
I have tried a number of things, though none with much understanding (presumably my problem!).
I have called setTranslatesAutoresizingMaskIntoConstraints: NO on the label.
I have set the label's autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin. I have tried setting preferredMaxLayoutWidth to random values. Calling needsUpdateConstraints on the label. I tried putting the call to sizeToFit in viewDidLayoutSubviews.
I have come to the conclusion I need a little more understanding how I should be approaching this. Is sizeToFit not the thing to be calling when Auto Layout is on? Do I need to prod Auto Layout in some way after calling sizeToFit? I notice that rotating the simulator seems to center the label so prodding sounds a possibility?
I have re-read the Apple Auto Layout guide but I'm afraid I'm still not sure what I am doing wrong and the debugging tips suggested (visualizeConstraints etc) don't seem to work on iOS.
Thanks for any clue you can spare.
My idea about having to prod appears to be correct. After calling sizeToFit I needed to call [label.superview setNeedsLayout]. Whilst this works I'm not really sure why I need to do this manually rather than the label marking the layout as dirty when it's size changes.

SSRS: Report label position dynamic

I have a report which displays customer address in multiple labels.
My customers use windowed envelopes for mailing. I need the address labels position to be configurable.
Something like, I'll have a database table which stores the Top/Left position of each label per customer. Based on this table, I need to position the address labels on my report.
I thought, it is doable by expressions, but Location property doesn't provides ability to set an expression and make the label's top and left dynamic.
Anybody, any ideas, on how to achieve this?
As you mentioned, you cannot set an expression for location property. I want to do this before but it seems that there is no solution for this work.
Sorry for the duplicate post
I had the same problem as you did. I got around the problem by using an old HTML trick. It involves using a transparent.gif in an image. You put your image (linked to the gif), then put your label on top. Using a parameter, you can toggle which item to appear by setting an expression in the hidden property for both controls.
As stated by others, it isn't supported. However, here are two ugly work around possible for basic reporting.
Work around with padding.
You can't set formula on the label's location, but you can use padding option instead.
So you can set the label as wide as the report and as tall as the region.
Also, set the label's horizontal alignment to "Left" and Vertical alignment to "Top".
Then, add a formula in left and top paddings to offset the text.
You can also achieve a right aligned offsetted label by setting the Horizontal alignment to "right" and using right padding instead of the left one to offset the field from the right. With the same recipe, you can offset from the bottom by using "bottom" vertical alignment and bottom padding.
The ugly side:
This method will create a mess in the report designer as all dynamic label will overlap each other and take all the space over static label. Also, please note that with this method, you won't be able to do fancy stuff like adding borders around the text and hyperlinks.
Work around with sub report.
If the number of different positions for the label(s) are really low. You can create a subreport for each possibility and use a formula to display the right subreport for the right case. Sadly, this doesn't work for labels in the header as subreport aren't allowed there.
No solution, as it is not supported!!!
From MS online community support...
"As far as I know, the position of the textbox in the report is static not dynamic, so it will not shift to left."
Reference: http://forums.asp.net/t/1433297.aspx

Resources