[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.
Related
I'm searching for idea how to implement a table view with moving view on top of it.
So the idea is something similar to navBar in facebook app. When you scroll up this (red) view is moving up and hiding, when you scroll up its going up and when you scroll down its revealed. This is not nav bar so most of the pods I've found are not working in this situation. This cannot be tableView header or section header as well.
You need added this view above table:
[self.tableView.superview insertSubview:view aboveSubview:self.tableView]
Or you can do it in storyboard.
When you table scroll down hide view, when up show.
[view setHidden:YES];
Also u could change table inset to the top of the superview.
self.tableView.contentInset = self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(self.tableView.contentInset.top -, self.tableView.contentInset.left, self.tableView.contentInset.bottom, self.tableView.contentInset.right);
I think fast way to do it use gesture recognizers to recognize reveal and hide actions and than you can use methods like below,
[UIView animateWithDuration:0.5 animations:^{
[attachedView setAlpha:0.0f];
} completion:^(BOOL finished) {
[attachedView setHidden:YES];
}];
and for reveal attached view
[UIView animateWithDuration:0.5 animations:^{
[attachedView setAlpha:1.0f];
} completion:^(BOOL finished) {
[attachedView setHidden:YES];
}];
methods will help you to hide and reveal views gently.
Take a look at this library, it does exactly what you want to do
https://github.com/telly/TLYShyNavBar
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
How can I flip a view with a label on the front side and another label on the back side when a button is clicked? Something that looks like the image below.
What would be the logic to create this effect?
Thanks
EDIT:
Sorry about the confusion but please note that I'm just talking about a view not ViewControllers, this effect will happen within the same viewController. I have updated the image to reflect that the view I'm talking about is a subView inside the main view.
I too had something very similar situation, on click of a button on ViewController1 I have to move to another ViewController2. I used this code,
//code this in ViewController1
-(IBAction)flipView:(id)sender
{
ViewController2 *view2 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
[UIView beginAnimations:#"animation" context:nil];
[UIView setAnimationDuration:1.0];
[[self navigationController] pushViewController:view2 animated:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[view2 release];
}
//code this in ViewController2 on click of back button
-(IBAction)flipView:(id)sender
{
[UIView beginAnimations:#"animation" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[[self navigationController] popViewControllerAnimated:YES];
[UIView commitAnimations];
}
But in this code I am using 2 classes, if it is fine to you, use this code. Hopes it solves your problem to some extent.
What you can do is use two UIViews, one for the first side, one for the second side.
Show the first view, hide the second view, and set the second view's frame to have a width of 0.
Then, when your first view is visible, animate its frame to have a width equal to 0. Hide the first view, unhide the second view, and animate the second view's frame to the desired frame.
Edit : This does not appear to work well if you have labels in your views, as this is a 2D flip. Sorry about that. #Maverick's answer could work pretty well in your case.
Call this method in your viewController, your viewController view flips and viewController life cycle method calls and simply change the image of UIImageView you want to display in
-(void)viewdidload method.
[UIView beginAnimations: #"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
UIView *parent = self.view.superview;
[self.view removeFromSuperview];
self.view = nil; // unloads the view
[parent addSubview:self.view]; //reloads the view from the nib
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
Please vote up if you find it helping
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
In storyboard, in a view controller i've added a scroll view.Inside it another two different views are added & named them as "firstview" & "secondview". When i press add button from "firstview" ,it will show SecondView which is kept as hidden during the initial run. Now i want to display that view by performing some animations. How to solve this?
[UIView transitionWithView:self.secondview
duration:5.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.secondview.alpha = 1.0f;
} completion:NULL];
tried these but not working
Thanks in advance....
Try the following code if your second view is hidden
[UIView transitionWithView:self.secondview duration:5.0f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
self.secondview.hidden = NO;
} completion:^(BOOL finished) {
self.secondview.alpha = 1.0f;
}];
If your self.secondview is hidden then you need to make it unhidden and set the alpha to 0. If the secondview is hidden that doesn't mean it's alpha is 0.
So use the same code but instead of make it hidden set the secondview.alpha = 0; or in your case make it from the storyboard.