Animating a container view code - ios

I have an app with two UIViews in a IB ViewController. Each of these is a container view having two UIImageViews.
I use Core Motion gravity to move these views as the device is tipped. There are also two UIImageViews in the IB view.
I am trying to animate the UIImageViews inside the container views. However, when the animation happens, it takes place immediately instead of taking place over 5 seconds that I specify in the annimation.
I have tried to animate the container view and the UIImageViews but the same thing occurs.
Any ideas?
This is my code
[UIView animateWithDuration:5 delay:0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
[self.myView setFrame:0,0,11,23self.myView2 setFrame:0,0,11,23))];
)];
}
completion:^(BOOL finished
This changes the size of the container view Myview and myview2.

Your code is:
[UIView animateWithDuration:5 delay:0
Buw that you want to achieve is:
[UIView animateWithDuration:5 delay:5

Related

Animate image view inside a container view in iOS?

I'm trying to animate a image view inside a container view.
Container view is square and aligned center of the screen. i do have a image view inside my container. position of my image view is shown in below screenshot.(super view is my container view)
i want to animate the image view inside the container like from top 0 to bottom 0 so i tried animating from top 0 to top maximum (that is height of the container view) but it is not working as expected. My expected output is something like the image view should animate inside container view continuously from top to bottom and reverse.
animation method which i tried is
int maxTop = self.containerView.frame.size.height/2;
self.topConstraint.constant = maxTop;
[self.imageView setNeedsUpdateConstraints];
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse animations:^{
[self.imageView layoutIfNeeded];
} completion:nil];
EDIT:
Here is the current output GIF. It is not moving to full height
The animation should be started after viewDidAppear, so the parent view could align itself properly.
Try
[UIView beginAnimations:nil context:nil;
[UIView setAnimationDuration:0.5];
[self.topConstraint.animator setConstant:maxTop];
[UIView commitAnimations];
As in your original code you didn't set the constraint's constant inside the animation

Custom UIActivityViewController-like view that slides up and down

Is there a way to subclass or customize UIActivityViewController to create a sort of custom view? For example, see the image below from the app Overcast. I want to create a view similar to that, where if you tap a button, the view pops up and when you tap outside of the view, it slides back down.
Why not use an UIView ? Set it's initial frame's y value to -self.customView.frame.size.height and animate it's frame to the normal position using [UIView animateWithDuration]
-(void)showCustomView{
[self.customview setFrame:CGRectMake(0, -self.customView.frame.size.height, self.view.bounds.size.height+self.customView.frame.size.width, self.customView.frame.size.height)];
[UIView animateWithDuration:0.25 animations:^{
[self.customView setFrame:CGRectMake(0, -self.view.frame.size.height, self.view.bounds.size.height-self.customView.frame.size.width, self.customView.frame.size.height)];
}];
}
-(void)hideCustomView{
[UIView animateWithDuration:0.25 animations:^{
[self.customView setFrame:CGRectMake(0, -self.customView.frame.size.height, self.customView.bounds.size.height+self.customView.frame.size.width, self.customView.frame.size.height)];
}];
}
Add an UITapGestureRecognizer and call hideCustomView when tapped outside the customView

Half Hidden view under the main view is showing in alpha segue

[sourceViewController.view addSubview:destinationController.view];
[destinationController.view setFrame:sourceViewController.view.window.frame];
[destinationController.view setTransform:CGAffineTransformMakeScale(0.5,0.5)];
[destinationController.view setAlpha:0.0];
[UIView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationCurveEaseOut
animations:^{
[destinationController.view setTransform:CGAffineTransformMakeScale(1.0,1.0)];
[destinationController.view setAlpha:1.0];
//[sourceViewController.view setAlpha:0];
}
completion:^(BOOL finished){
[destinationController.view removeFromSuperview];
[sourceViewController.navigationController pushViewController:destinationController animated:NO];
}];
My destinationController has 2 views one over the other. View #1 is the main view and totally visible and View #2 that is half visible half hidden. When I use the code above and move between segues I can see (while going from alpa 0 to 1) the hidden view completely under the main view. So the user can see what is hidden under there. (even if I make the animateWithDuration really fast). I don't know why this is happening and trying to find a creative solution. One solution I came up with is using an animation inside the ViewController
[UIView animateWithDuration:0.7 animations:^() {_image.alpha = 1;}];
and by that "slowing down" the hidden view but obviously the view is loaded in a delay and doesn't look so elegant on the visible part of the hidden view.
Thanks
You could hide the partly hidden view first, just before your animation, or set up another animation (which will run concurrently) to set the hidden view's alpha to 0. Run this animation at the same or faster rate than your main view animation.

UIView animation doesn't get called when view is reloaded

I have programmed the following animation for an UIImageView which works fine when I load the View:
-(void) viewDidAppear:(BOOL)animated{
[UIView animateWithDuration:2
delay:0
options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{
hat.transform = CGAffineTransformMakeRotation(0.2);
}completion:nil
];
}
Then I push a new View Controller on top of this view, but when I pop this new view controller, the animation doesn't fire... I've tried placing this animation code in viewDidload and in viewWillAppear but that didn't help... Any thoughts?
is it possible that the UIImage view is getting unloaded? If you haven't already try setting strong/retain property to your UIImageView.

Animating UITableView resize

Im using the following code to animate the resizing of a UITableView to make way for a UIView with extra controls when the UITableView.isEditing.
[UIView animateWithDuration:3 // 0.2 but slowed down to easily see difference
delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
[self.selectControlsView setFrame:CGRectMake(0, self.tableView.frame.size.height-self.selectControlsView.frame.size.height, self.selectControlsView.frame.size.width, self.selectControlsView.frame.size.height)];
[self.tableView setFrame:CGRectMake(0, 0, self.tableView.frame.size.width, self.tableView.frame.size.height-self.selectControlsView.frame.size.height)];
}
completion:nil];
This works fine except it seems the UITableView animates faster than the UIView does (even though I adjust the UIViews frame before the UITableViews frame), causing a black flicker during the animation from the background.
Is there a way to animate the two views in tandem?
The problem was caused because the controller was a subclass of UITableViewController. I'm now subclassing UIViewController and adding the UITableView as a subview, the animation for adding the new view and resizing the UITableView now works as expected.

Resources