Copying frame/bounds/constraints from one view to another - ios

self.blurView = UIVisualEffectView(effect: UIBlurEffect(style: .ExtraLight)) as UIVisualEffectView
self.blurView.frame = self.filterPanel.frame
self.blurView.bounds = self.filterPanel.bounds
self.blurView.addConstraints(self.filterPanel.constraints())
self.view.insertSubview(self.blurView, belowSubview: self.filterPanel)
When attempting to run the code above in viewDidLoad it returns the error below. Why is this? I am simply trying to create a blur view with the same dimensions as the filterPanel view.
2015-02-15 14:44:37.929 App[568:182030] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x18eeac70 H:|-(0)-[UIView:0x1bbe0a70] (Names: '|':UIView:0x1bbe0a00 )>
When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView _viewHierarchyUnpreparedForConstraint:] to debug.
2015-02-15 14:44:37.944 App[568:182030] *** Assertion failure in -[UIVisualEffectView _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:], /SourceCache/UIKit/UIKit-3318.16.25/NSLayoutConstraint_UIKitAdditions.m:560
2015-02-15 14:44:37.945 App[568:182030] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Impossible to set up layout with view hierarchy unprepared for constraint.'
*** First throw call stack:
(0x229ba49f 0x30174c8b 0x229ba375 0x2368bd1f 0x264a4295 0x25f63cd3 0x25f63b3f 0x25f63ab3 0x264a43d1 0x25f6c909 0x25f6c87d 0xffe30 0x1019dc 0x25e7b52f 0x25f25385 0x25f252ad 0x25f24843 0x25f24573 0x25f242dd 0x25f24271 0x25e78a6f 0x258a0a0d 0x2589c3e5 0x2589c26d 0x2589bc51 0x2589ba55 0x260dc885 0x260dd62d 0x260e7a39 0x260dba47 0x2914b0d1 0x22980d7d 0x22980041 0x2297e7c3 0x228cc3c1 0x228cc1d3 0x25edf9cf 0x25eda7b1 0xbd574 0xbd690 0x306f4aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Thanks in advance.

The constraints self.filterPanel.constraints() all presumably relate to self.filterPanel and its subviews. Setting those constraints on self.blurView doesn't magically change them to refer to self.blurView and its subviews. You're adding constraints to a view that has nothing to do with it or its subviews.
You would need to go through all of the constraints and build new constraints that are parallel in form but refer to the corresponding view within the self.blurView sub-hierarchy, which is not going to be easy. For one thing, you've just created self.blurView so it presumably has no subviews, yet.
You might try encoding the original view to an archive and then decoding that archive to produce a duplicate sub-hierarchy.

Related

Terminating app due to uncaught exception [UIImageView _isResizable]

I'm getting an exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView _isResizable]: unrecognized selector sent to instance 0x7fe01fd0d470'
I just assigned an image to the imageView inside a custom cell using storyboard.
The code is clean. It doesn't have any warnings or errors.
Two reason of this error.
If you want to assign image write.
cell.image=[UIImage imagenamed:#"Name of your image "];
and another reason of this error is you can cut the link of imageView to the outlet.
Again make a new outlet and then check now imageView is working.
i think this will help u.
there may be two or more outlet references to one imageView which makes ambiguous
Please see once the name of image in swift file and StroryBoard. Compare them they must be same.
Also check the identifier of Cell.

CALayerInvalidGeometry crash on iOS9 "sublayer with non-finite position [inf inf]"

iOS 9, Swift 2: I've got a view controller with a custom view that crashes whenever I pop it from it's navigation controller stack, citing the following crash:
*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'sublayer with non-finite position [inf inf]'
There is far too much going on in the view controller to post here (it's what i'm in the middle of cleaning up) but was wondering if anyone has experienced a similar issue?
I've seen sublayer with non-finite position [inf inf] and a related question, but neither resolve the problem. There is no CGRectNull to be found in the entire code base, so i'm a bit stumped.
And of course as soon as I post the question after 30 minutes of struggling, I finally crack it.
There were a whole bunch of subViews that were being added to the view elsewhere in the view controller that I wasn't aware of. The main view is using constraints based layout while these subviews were being created with a frame and then added as a subview.
I'm not sure why it was causing a crash, but after removing all the rogue subviews all was well.
I'll keep this question/answer alive in case anyone else has the same issue.

Application crashes in iOS 7 when place holder text is added to text field

My application crashes in ios7 when i add a placeholder to text field ,the same works fine in ios8. Added controls programmatically with auto layout
As suggested i added [self.view layoutIfNeeded]; at the end of viewDidLayout delegate method but still the app crashed with the below exception
Assertion failure Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UITextField's implementation of -layoutSubviews needs to call super.'
It is very important where you add your constraints programmatically. You should not add them in one of the layouting methods callbacks (like layoutSubviews or viewdidLayoutSubviews). That is because the system is expected to have the views layout after these methods are called and if you add new constraints after the views were already layouted and a new layout cycle is needed, there will be a crash.
I suggest you think about another method where you could add the new constraints. If there is no other place that would work for you, try adding the constraints before you call the super method, not the other way around.
So something like this:
- (void)viewDidLayoutSubviews {
// Add constraints
[super viewDidLayoutSubviews];
}
If you could post some of your code, I would me more than happy to help you further :)

Error when moving view Controller

I get an error saying
*** Assertion failure in -[HatsViewController loadView], /SourceCache/UIKit/UIKit-2380.17/UICollectionViewController.m:104
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UICollectionViewController loadView] loaded the "FCD-ki-UFO-view-1vb-8P-s3C" nib but didn't get a UICollectionView.'
*** First throw call stack:
(0x3467c2a3 0x3c36097f 0x3467c15d 0x34f51ab7 0x368aaa95 0x364a346d 0x3652f353 0x36570d11 0x3656ffe7 0x366923ef 0x3656f0c5 0x3656f077 0x3656f055 0x3656e90b 0x3656ee01 0x364975f1 0x36484801 0x3648411b 0x3818b5a3 0x3818b1d3 0x34651173 0x34651117 0x3464ff99 0x345c2ebd 0x345c2d49 0x3818a2eb 0x364d8301 0xc0dfd 0x3c797b20)
libc++abi.dylib: terminate called throwing an exception
(lldb)
Why does this happen and how can I fix it?
When you’re using a UICollectionViewController, the view outlet needs to be connected to a UICollectionView in your storyboard; if it’s a UIView of another class, it’ll crash.
check HatsViewController.h is inherited from UICollectionViewController but you have connected it view in your storyboard. Either it must be subclass of UIViewController or it is connected to UICollectionView in your storyboard.

Constraint must contain a first layout item NSLayoutConstraint

I had my LayoutConstraints working fine, then all of a sudden I started getting this when adding Constraints to my view.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]: Constraint must contain a first layout item'
*** First throw call stack:
(0x7cd012 0x2017e7e 0x7ccdeb 0xde6bf1 0x9c487 0x994a3 0x414fb 0x20224 0x5c6c0 0xc30e83 0x78c376 0x78be06 0x773a82 0x772f44 0x772e1b 0x28eb7e3 0x28eb668 0x149465c 0x2cfd 0x2c25)
libc++abi.dylib: terminate called throwing an exception
And there exists no immediate documentation on the internet or on the Apple Docs as to what the error message means.
Just wondering if anyone has encountered this error, and know what I can do to troubleshoot it?
One more reason for this error/crash can be, the views passed to the [NSLayoutContraint constraintWithItem ...] method are nil.
Ah, found the issue.
For anyone who has this issue, it's because the view hasn't been created in the nib/UIView yet, so no constraints can apply.
I moved the Constraint code from the initWithNib method to viewDidLoad and the error naturally stopped occurring.
If you're hanging on to your views with properties make sure they're strong! This could account for them being nil.
This can also happen if you switch off Autolayout for some reason, but you're still adding constraints to any subview via code (e.g. for handling orientation changes)
This happened to me when I used to different NIB's for the iPhone and iPad and switched off Autolayout for only the iPhone NIB while using a common .m file.
Solution is to check for the device type and skip the layout addition where it's not needed.
This happened when I accidentally deleted the 'referencing outlet' for one of my UI elements.

Resources