AnchorView | An example of an AnchorView that enables relative layouting | Router library
kandi X-RAY | AnchorView Summary
kandi X-RAY | AnchorView Summary
An example of an AnchorView that enables relative layouting in RelativeLayouts
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of AnchorView
AnchorView Key Features
AnchorView Examples and Code Snippets
Community Discussions
Trending Discussions on AnchorView
QUESTION
To me it looks like the safe area of a view is not updated after the owning view controller's .viewWillDisappear()
method is called.
Is this intended or a bug in the framework?
The issue is easily visualised by creating a custom UIViewControllerTransitioningDelegate
that animates a smaller view in one view controller, to full screen size in another (constrained to safe areas). Then the safe area will expand as the present animation goes on (as expected), but will not shrink as the dismiss animation goes on (not expected!). The expected behaviour would be that the safe area expands during the present animation, and shrinks during the dismiss animation.
The gif below shows the unexpected behaviour. The grey area of the presented view controller is the safe area.
Below is the code I used to visualise this problem. ViewController.swift
presents MyViewController.swift
using FullScreenTransitionManager.swift
ANSWER
Answered 2021-Dec-22 at 21:57As confirmed by the answer on this post on the Apple Developer forums, this behaviour is expected. And safe areas is not updated if a view controller is not in the appearing state (between viewWillAppear and viewWillDisappear)
QUESTION
So, straight to the problem:
I've created a custom UIViewControllerTransitioningDelegate that I use to animate a view from one view controller, to full-screen in another view controller. Im doing this by creating UIViewControllerAnimatedTransitioning-objects that animate the presented view's frame. And it works great! Except when I try to adjust the additionalSafeAreaInsets of the view controller owning the view during dismissal...
It looks like this property is not accounted for when I'm trying to animate the dismissal of the view controller and its view. It works fine during presentation.
The gif below shows how it looks. The red box is the safe area (plus some padding) of the presented view - which I'm trying to compensate for during animation, using the additionalSafeAreaInsets property of the view controller owning the view.
As the gif shows, the safe area is properly adjusted during presentation but not during dismissal.
So, what I want is: use additionalSafeAreaInsets to diminish the effect of the safe area during animation, by setting additionalSafeAreaInsets to the "inverted" values of the safe area. So that the effective safe area starts at 0 and "animates" to the expected value during presentation, and starts at expected value and "animates" to 0 during dismissal. (I'm quoting "animates", since its actually the view's frame that is animated. But UIKit/Auto Layout use these properties when calculating the frames)
Any thoughts on how to battle this issue is great welcome!
The code for the custom UIViewControllerTransitioningDelegate is provided below.
...ANSWER
Answered 2021-Dec-19 at 18:12After some debugging I managed to find a workaround to this problem.
In short, it looks like the safe area is not updated after UIViewController.viewWillDisappear
is called, and hence any changes to .additionalSafeAreaInsets
is ignored (since these insets modifies the safe area of the view controller's view).
My current workaround is somewhat hacky, but it gets the job done. Since UIViewControllerTransitioningDelegate.animationController(forDismissed...)
is called right before UIViewController.viewWillDisappear
and UIViewControllerAnimatedTransitioning.animateTransition(using transitionContext...)
, I start the dismiss animation already in that method. That way the layout calculations for the animation get correct, and the correct safe area is set.
Below is the code for my custom UIViewControllerTransitioningDelegate
with the workaround. Note: I've removed the use of .additionalSafeAreaInsets
since its not necessary at all! And I've no idea why I thought I needed it in the first place...
QUESTION
So, straight to the point:
I’m using a custom UIViewControllerTransitioningDelegate, that provide a custom UIPresentationController and present/dismiss animations, to animate a view from one view controller to another. When an image is taped in a table view cell in the first view controller, the image is presented in full screen in the second view controller, animating from its position in the table view cell to its position in the presented view controller.
The gifs below shows what is going on. Note that everything works smooth for the present animation, but not for the dismiss animation.
The issue I’m having is that when the dismiss animation fires, it looks like the frame of the animated view gets offset or transformed in a way. And I cant figure out why! The frame at the start of the animation is untouched (by me at least), and the frame at the end of the animation is the same as the frame for the present animation - which works perfectly fine!
Anyone has any idea of what is going on?
The code for my custom UIViewControllerTransitioningDelegate is provided below.
...ANSWER
Answered 2021-Dec-18 at 11:59I managed to figure it out after playing around for a good while. And I think I've had a feeling about what the the problem was all along...
Short answer:
Do not try to animate views by changing their .frame
or .bounds
when using Auto Layout Constraints. Changing these properties might cause undefined behaviour (like the one I experienced). Instead, animate views by changing their constraints or the .center
and/or .transform
property. These properties do not conflict with the layout engine. When querying a view for its size, use the .bounds
property, since this property is more reliable than .frame
when using Auto Layout Constraints.
Slightly longer answer:
Since I was using Auto Layout Constraints all over the place, combining it with manually changing the frames of views during animation did not work. Or more correct - had undefined behaviours. Since the Auto Layout Engine uses constraints to modify the view's frame for you, you should avoid touching the .frame
(and .bounds
) property yourself. Instead, animate your views by changing properties like .center
and .transform
. It seems like these properties do not conflict with Auto Layout, and changes to these properties will be applied to your views after the Auto Layout Engine has done its calculations. Event thought changing the .frame
and .bounds
of the view might work sometimes in combinations with Auto Layout Constraints, like I experienced with my custom presentation animation (which seemed to work flawlessly!), you should really avoid it. A workaround in some cases might be to temporary turn .translatesAutoresizingMaskIntoConstraints == true
, but this is really not a god idea since it causes UIKit to generate Auto Layout Constraints for you, and those constraints might conflict with your own constraints. When querying a view for its size, use the .bounds
property, since this property is more reliable than .frame
when using Auto Layout Constraints and the .transform
property.
Worthy mentions from the Apple documentation:
UIView.center
:
Use this property, instead of the frame property, when you want to change the position of a view. The center point is always valid, even when scaling or rotation factors are applied to the view's transform. Changes to this property can be animated.
UIView.transform
:
In iOS 8.0 and later, the transform property does not affect Auto Layout. Auto layout calculates a view’s alignment rectangle based on its untransformed frame.
Warning: When the value of this property is anything other than the identity transform, the value in the frame property is undefined and should be ignored.
UIView.translatesAutoresizingMaskIntoConstraints
:
If this property’s value is true, the system creates a set of constraints that duplicate the behavior specified by the view’s autoresizing mask. This also lets you modify the view’s size and location using the view’s frame, bounds, or center properties, allowing you to create a static, frame-based layout within Auto Layout.
Note that the autoresizing mask constraints fully specify the view’s size and position; therefore, you cannot add additional constraints to modify this size or position without introducing conflicts. If you want to use Auto Layout to dynamically calculate the size and position of your view, you must set this property to false, and then provide a non ambiguous, nonconflicting set of constraints for the view.
By default, the property is set to true for any view you programmatically create. If you add views in Interface Builder, the system automatically sets this property to false.
For those interested, below is my final code for the custom UIViewControllerTransitioningDelegate
. Only using Auto Layout Constraints, and only modifying the view properties mentioned above.
Note: I'm using TinyConstraints to make writing constraints more pleasant.
QUESTION
When I set snackbar.anchorView = adContainer my FAB doesn't float.
...ANSWER
Answered 2020-Dec-19 at 15:55I can't write simple comment sorry about that. Can you try to add in your Manifest file below which activity you try to do that
android:windowSoftInputMode="adjustResize"
QUESTION
I added aListPopupWindow
anchored to a TextInputLayout
. The issue I have with this is that the animation for the popup starts within the TextInputLayout
:
Note that the issue is just where the animation starts. After the animation has finished, the popup is correctly shown below the TextInputLayout
.
What do I have to do to let the animation start just below the TextInputLayout
? Note that it's not my own animation, but the default one.
Layout snippet:
...ANSWER
Answered 2020-Aug-15 at 10:33You can use setEpicenterBounds(Rect) and pass a Rect width the full width but a flat height at the bottom of the anchor.
Obviously the anchor view needs to be already laid out when calling setEpicenterBounds(Rect)
because its size is needed, the best place for the call is probably right before show()
, if you really can't do it there and the anchor view is not using fixed sizing, you might use a ViewTreeObserver.OnGlobalLayoutListener
.
QUESTION
Currently my popup is overlapping other views. setElevation(0)
changes nothing. setOverlapAnchor(false)
and setAttachedInDecor(true)
also don't help much. Below is the code I have used. I need the popup to be located under navigation drawer
ANSWER
Answered 2020-Jan-22 at 17:14PopupWindow is a window. Your navigation drawer is located on another window with its own view hierarchy.
Its like this:
-- activity
---- window1
------ viewhierarchy
--------NavigationDrawer
---- window2
------ popup
What you want is not possible using PopupWindow.
One possible work-around is to hide & show the popup when navigation is opened and closed. Here's the callback:
Or you may add a view as popup by yourself and take care of the positioning and gravity.
Last but not least, check out these libraries as they may have what you want. They work with view so you may manage it the way you want.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install AnchorView
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page