ObjectAnimator in Android doesn't update the View's parent - animation

Objective:
Build a SlideUp animation in a ImageView with fixed height that is placed in a LinearLayout with wrap_content height.
Problem:
The animation runs normally, but the parent LinearLayout doesn't resize itself while or after the animation occurs. I mean, if it is set to "wrap_content" and the "content" changes it's position (y axis to -100), it's expected that the parent accompanies the animation, "animating" it's height to 0 as well, or not?
How can I force it to continue "wraping" the content while the animation runs?
PS: No, it's not about fillAfter, I'm using ObjectAnimator, which changes the real object properties, not only the View drawn. For instance, the click event is not being triggered on the place the image used to be before the animation.
My code:
ObjectAnimator oa = ObjectAnimator.ofFloat(findViewById(R.id.menu_tile_image), "y", 0, -100);
Layout structure:
LinearLayout (match_parent, wrap_content) > ImageView (fill_parent, 100)
Any clue on that? Thanks!

Related

Issue on Collection View performBatchUpdate when animating a height change of an Item

There is a problem when using performBatchUpdates method to animate a height change on a CollectionViewCell when this results on new items appearing on-screen that were off-screen before the animation ran. In this case scenario the items initially positioned off-screen appear at their final location instead of being animated there.
I found this workaround to avoid this undesired behavior on this Github page.
The trick is done by changing the height of the CollectionView before running the animation and setting it back to the original value on the completion block of the performBatchUpdate Method.
This is what the code could look like:
frameUpdate.size.height += kExpandedHeight - kCollapsedHeight;
collectionView.frame = frameUpdate;
[collectionView performBatchUpdates:^{
_cells[indexPath.item] = #(newHeight);
} completion:^(BOOL finished) {
frameUpdate.size.height -= kExpandedHeight - kCollapsedHeight;
collectionView.frame = frameUpdate;
}];
For a full project sample of this workaround go to the Github page
https://github.com/jpsim/UICollectionView-Animation-Bug
Thanks for sharing JP Simard!

Xcode - viewDidLayoutSubviews

i have a view inside a viewController, i wanted to start the smaller view outside the viewController in the left, and animate it to the centre when i press a button. so i made it like this:
override func viewDidLayoutSubviews() {
smallView.center = CGPointMake(smallView.center.x - 400, smallView.center.y)
}
And it works perfectly!, the problem is i have a text view inside that smaller view, and every time i start editing it it jumps outside of the main viewController right where it was, and i have to press the button again to bring it inside.
How to fix this?
PS: i tried positioning it to the centre when i start editing the text view like this:
func textViewDidBeginEditing(textView: UITextView) {
smallView.center = CGPointMake(smallView.center.x + 400, smallView.center.y)
}
But it doesn't work. and the method is connected to the textView properly(delegate)
PS2: i also have imagePickerController inside my viewController.
OK, as you're using Auto Layout.
The first rule of Auto Layout (you will see this in any Auto Layout book) is that you absolutely cannot touch the frame or center of a view directly.
// don't do these
myView.frame = CGRectMake(0, 0, 100, 100);
// ever
myView.center = CGPointMake(50, 50);
You can get the frame and center but you can never set the frame or center.
In order to move stuff around using Auto Layout you need to update the constraints.
For instance if I set up a view called myView and want it to grow and shrink in height I would do something like...
Set the top constraint to the superview at 0.
Set the left constraint to the superview at 0.
Set the right constraint to the superview at 0.
Set the height constraint to 50 (for example) and save it in a property called heightConstraint.
Now to animate the change in height I do this...
self.heightConstraint.constant = 100;
[UIView animateWithDuration:1.0
animations:^ {
[self.view layoutIfNeeded];
}];
This will then animate the height from 50 (where it was when I set it) to 100.
This is the same for ANY animation of views using Auto Layout. If (for instance) I had saved the left constraint I could change that and it would increase and decrease the gap from the left edge of the superview to myView.
There are several really good tutorials about AutoLayout on the Ray Wenderlich site. I'd suggest you take a look at them.
Whatever you do, I'd strongly suggest not just disabling Auto Layout. If you don't know how to use Auto Layout then you will very quickly fall behind with iOS 8 and the new device sizes.

Resize all uiscrollviews in a container uiscrollview

Hierarchy is a fullscreen landscape container UIScroll. Inside are multiple fullscreen pages made up of uiscrollviews with images inside - this allows paging plus pinching /zooming of the inner scrollviews. You can scroll up and down.
I want to resize the width of the container scrollview and have the nested uiscrolls and images within them resize proportionally and dynamically to the new width and height.
My outer scroll has autoresize to yes, my inner scrolls have the same. And I also have my uiimageviews on auto as well.
Right now the frame of the container scroll just crops off the inner content.
Any thoughts?
I ended up adding code to a function that allowed me to scale the interior of the scrollview the way I wanted.
[containerscrollView setFrame:CGRectMake(200.0f, 0.0f, 800.0f, 768.0f)];
containerscrollView.contentSize = CGSizeMake(800,containerscrollView.frame.size.height * scrollArrayCount);
for (UIScrollView *tmp in [containerscrollView subviews]) {
if (tmp.tag>4000) // make sure to only resize the inner scrollview {
[tmp setFrame:CGRectMake(tmp.frame.origin.x, tmp.frame.origin.y, 800.0f, 768.0f)];
_innerScrollView.contentSize =CGSizeMake(800.0f, 768.0f);
}
}

iOS animation: Drop down that keeps it position

I´m trying to create a drop down menu that will display a set of controls. I got the animation working but the whole "button" moves with the animation.
My button is a UIView which is named settingsPanel, this is my code so far:
[UIView animateWithDuration:1.0f animations:^{
self.settingsPanel.bounds = CGRectMake(self.settingsPanel.bounds.origin.x, self.settingsPanel.bounds.origin.y, self.settingsPanel.bounds.size.width, self.settingsPanel.bounds.size.height + 300);
}];
I just want the height of the panel to change, and it does, but the whole view moves up a bit as well.
How can I create a animation that justs increases the height downwards?
You need to set the frame, not the bounds.
[UIView animateWithDuration:1.0f animations:^{
self.settingsPanel.frame =
CGRectMake(self.settingsPanel.frame.origin.x,
self.settingsPanel.frame.origin.y,
self.settingsPanel.frame.size.width,
self.settingsPanel.frame.size.height + 300);
}];
Frame is an external coordinate. When you change the frame, you change the actual position of the view within its superview, so you can keep the origin and width the same and just increase the height.
Bounds is an internal coordinate. When you change the bounds, the system has to decide what to do about the frame; its solution is that the change happens around a stationary center position. So the top moves upward as the height grows downward.

FabricJS Canvas, Scrolling parent container moves child hit area

I am using FabricJS to create an application. I am finding that scrolling a parent div/container offsets the selectable area of an object to the right in direct relation to amount scrolled.
So, if I have a canvas that is 1200x600 and a container div that is 600x600 and I add a rect to that canvas at 400, 120; when I scroll 200px, I can't click on the rect to select it. Rather, I have to move my mouse to 600, 120 (empty space) to get the cross bar and select the rect.
Not sure if this is known, or has a work around - but I would appreciate any help possible.
You'll have to modify FabricJs code to make it work.
The problem is in the getPointer function, if you search for it in all.js you'll notice the comment "this method needs fixing" from kangax.
A workaround can be substituting this function with
function getPointer(event) {
// TODO (kangax): this method needs fixing
return { x: pointerX(event) + document.getElementById("container").scrollLeft, y: pointerY(event) + document.getElementById("container").scrollTop };
}
where "container" is the wrapper div of you canvas. It's not nice, since you have to put the exact id, but it works.
Hope this helps.

Resources