I have a viewcontroller where I simulate an view on. I have a firstViewController and I have loginViewController. Here is the code how I popup the loginViewontroller on top of the firstViewcontroller.
in firstViewController.m
LoginViewController *login = [[LoginViewController alloc]initWithNibName:#"LoginViewController" bundle:NULL];
[self presentModalViewController:login animated:YES];
And in loginViewController I have the following function.
-(void)initialDelayEnded {
self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
self.view.alpha = 0.0;
[UIView animateWithDuration:1.0/1.5 animations:^{
self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
}completion:^(BOOL complete){
[UIView animateWithDuration:1.0/2 animations:^{
self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
}completion:^(BOOL complete){
[UIView animateWithDuration:1.0/2 animations:^{
self.view.transform = CGAffineTransformIdentity;
}];
}];
}];
}
In firstViewcontroller I have a background image. What I want to do now is that loginViewcontroller pops up the image is still visible.
Can anybody help me?
Thanks in advance.
You can't see through the viewcontroller stack. The easiest solution would be to pass the background image you have in firstviewcontroller to the second and set it as a background.
Have a property on LoginViewController.h
#property (nonatomic, strong) UIImage* image;
Then when you instantiate the controller
LoginViewController *login = [[LoginViewController alloc]initWithNibName:#"LoginViewController" bundle:NULL];
login.image = self.backgroundImage; //Set the image to the background image
[self presentModalViewController:login animated:YES];
Finally, in viewDidLoad of loginViewController.m
self.view.backgroundColor = [UIColor colorWithPatternImage:self.image];
Related
My application is displaying Arabic text in which i want push animation from left side and not from right side which ios provides by default.
I am using storyboards.I have created custom segue.
I have gone through all options cocoacontrols but have not found desired one.
I have found several options as follows:
1) CATransition
2) Animation
3) maintaining view controllers array - which creates lot of mess
Below code gives perfect effect but black patches as show below are not acceptable -
-(void)perform {
UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
UIViewController *destinationController = (UIViewController*)[self destinationViewController];
CATransition* transition = [CATransition animation];
transition.duration = .25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[sourceViewController.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[sourceViewController.navigationController pushViewController:destinationController animated:NO];
[destinationController.view setBackgroundColor:[UIColor whiteColor]];
}
Implemented below code give no black patches - but not desired animation
-(void)perform {
UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
UIViewController *destinationViewController = (UIViewController*)[self destinationViewController];
[sourceViewController.view addSubview:destinationViewController.view];
[destinationViewController.view setFrame:sourceViewController.view.window.frame];
[destinationViewController.view setTransform:CGAffineTransformMakeScale(0.5,0.5)];
[destinationViewController.view setAlpha:1.0];
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationCurveEaseOut
animations:^{
[destinationViewController.view setTransform:CGAffineTransformMakeScale(1.0,1.0)];
[destinationViewController.view setAlpha:1.0];
}
completion:^(BOOL finished){
[destinationViewController.view removeFromSuperview];
[sourceViewController.navigationController pushViewController:destinationViewController animated:NO];
}];
}
By changing above code - but i am not getting desired result
-(void)perform{
UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
UIViewController *destinationViewController = (UIViewController*)[self destinationViewController];
[sourceViewController.view addSubview:destinationViewController.view];
[destinationViewController.view setFrame:sourceViewController.view.window.frame];
[destinationViewController.view setAlpha:1.0];
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationCurveEaseOut
animations:^{
sourceViewController.view.frame = CGRectMake(sourceViewController.view.frame.size.width*2, 0, sourceViewController.view.frame.size.width, sourceViewController.view.frame.size.height);
}
completion:^(BOOL finished){
[sourceViewController.navigationController pushViewController:destinationViewController animated:NO];
}];
}
use below code In appDelegate.m - applicationDidFinishLaunchingWithOptions
self.window.backgroundColor = [UIColor whitecolor];
This is a custom segue in swift that uses the messy way, manipulates list of view controllers.. Anyway, I wanted to push to a view controller, but make it look like it was a pop, and I tried to do it with all sorts of animations, but in the end - for me, this was the most simplest way to get what I wanted as I don't have to maintain my code, if iOS styling changes and so on, as it uses general pop - it should remain the same as default pop in the system.. Anyway, to the code:
class ReversePushSegue : UIStoryboardSegue {
override func perform() {
let sourceViewController = self.sourceViewController as UIViewController
let destinationViewController = self.destinationViewController as UIViewController
var vcs : NSMutableArray = NSMutableArray(array: sourceViewController.navigationController.viewControllers)
vcs.insertObject(destinationViewController, atIndex: vcs.count - 1)
sourceViewController.navigationController.viewControllers = vcs
sourceViewController.navigationController.popViewControllerAnimated(true)
}
}
What it does - it adds destinationViewController to the list as second last and then pops to it..
I have TabBarController in my AppDelegate :
IBOutlet TabBarViewController *tab;
This is the main controller in my app.
and in one of the viewcontroller inside the tabs i want to add a UIButton that when the user press it all the tabcontroller will change to another uiviewcontroller with flip animation.
i tried to achive it with this method:
RadioMainVC *radioMainVC = [[RadioMainVC alloc] initWithNibName:#"RadioMainVC" bundle:nil];
UINavigationController *radioNav = [[UINavigationController alloc] initWithRootViewController:radioMainVC];
[UIView beginAnimations:#"animation" context:nil];
[self.tabBarController presentModalViewController:radioNav animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.tabBarController.view cache:NO];
[UIView commitAnimations];
And the flip won't work,any idea how to fix it?
Unfortunately I haven't tested this code but it might do the trick:
[UIView transitionFromView: self.tabBarController.view
toView: radioNav.view
duration: 0.5
options: UIViewAnimationTransitionFlipFromLeft
completion: ^(BOOL finished) {
window.rootViewController = radioNav;
}];
In my iPhone App I need to display a modal view with transparent background and it should appear with animation like it is appearing from center of view and its size is increasing.
similar like "drawing something" iPhone App when we click on settings button.
How do I do this?
You can do one of 4 following transition styles:
viewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
viewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:viewController animated:YES];
If you want something that is not included in these defaults you are going to have to build your own custom animation for presenting the modal view. Like the following but obviously for the style you want.
UIModalTransitionStyle horizontal movement
Let's say you have a viewController thats called aScoreSheet that you want to present. Try to define this method in the view controller that's going to do the presenting.
-(void) presentTransparentModalViewController: (ScoreSheet *) aViewController
{
scoreSheet = aViewController;
UIView *view = aViewController.view;
view.opaque = NO;
[view.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
UIView *each = obj;
each.opaque = NO;
}];
[self.view addSubview:view];
view.center = CGPointMake(160, 800); //for iPhone
[UIView animateWithDuration:0.9 delay:0 options:UIViewAnimationCurveEaseInOut animations:^{
view.center = CGPointMake(160, 240);
} completion:^(BOOL finished) {
self.view.userInteractionEnabled=YES;
}];
}
and then to dismiss the controller:
-(void) dismissTransparentModalViewControllerAnimated:(BOOL) animated{
if (animated) {
[UIView animateWithDuration:0.4
animations:^{
scoreSheet.view.center = CGPointMake(scoreSheet.view.center.x, scoreSheet.view.center.y + 480);
} completion:^(BOOL finished) {
[scoreSheet.view removeFromSuperview];
scoreSheet = nil;
}];
}
}
Not a full answer, but maybe you can take a look at this open source library:
https://github.com/Split82/HMGLTransitions
It has some custom modal transitions, maybe not exactly the one you are looking for, but you can easily add your transition by subclassing HMGLTransition.
Hope this helps
I want to load another view controller so the current slides up while the new one is coming from bottom, it works but I don't get the subviews (buttons disappear and I only get the blank view), how to fix it?
Current code is:
-(void)perform {
UIViewController *sourceVC = (UIViewController *) self.sourceViewController;
UIViewController *destinationVC = (UIViewController *) self.destinationViewController;
[UIView animateWithDuration:2.0
animations:^{
destinationVC.view.frame=CGRectMake(destinationVC.view.frame.origin.x, 480, destinationVC.view.frame.size.width, destinationVC.view.frame.size.height);
sourceVC.view.transform=CGAffineTransformMakeTranslation(0, -480);
destinationVC.view.transform=CGAffineTransformMakeTranslation(0, -480);
}];
}
You can create 2 views for your viewController, and set second view origin.y = window.height
Then animate like this -
CGRect outFrame = CGRectMake(0, 320, 320, 322);
[UIView animateWithDuration:0.50f
delay:delay
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
fromView.frame = outFrame;
toView.frame = CGRectMake(0, 0, 320, 322);
} completion:nil];
something like this...
What's the easiest/fastest/most efficient way to perform a gradual (0.5 sec) fade from Default.png to the initial app view?
My initial try, which doesn't work so well .. it's Saturday night, let's see if we can do better :)
UIImageView* whiteoutView = [[UIImageView alloc] initWithFrame:self.view.frame]; // dealloc this later ??
whiteoutView.image = [UIImage imageNamed:#"Default.png"];
whiteoutView.alpha = 1.0;
[self.view.frame addSubview:whiteoutView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelay:0.5];
whiteoutView.alpha = 0;
[UIView commitAnimations];
What about:
UIImageView* whiteoutView = [[[UIImageView alloc] initWithFrame:self.view.frame] autorelease];
if (whiteoutView != nil)
{
whiteoutView.image = [UIImage imageNamed:#"Default.png"];
[self.view addSubview:whiteoutView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: 0.5];
whiteoutView.alpha = 0.0;
[UIView commitAnimations];
}
(The things you had wrong were setAnimationDelay vs setAnimationDuration, not properly releasing the view and trying to add the view to self.view.frame instead of self.view. The compiler should have caught that last one. Did it?)
Here's a simple view controller that fades out the default image and removes itself from the view hierarchy. The advantage to this approach is that you can use this without modifying your existing view controllers...
#interface LaunchImageTransitionController : UIViewController {}
#end
#implementation LaunchImageTransitionController
- (void)viewDidLoad {
[super viewDidLoad];
self.view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Default.png"]] autorelease];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(imageDidFadeOut:finished:context:)];
self.view.alpha = 0.0;
[UIView commitAnimations];
}
- (void)imageDidFadeOut:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
[self.view removeFromSuperview];
//NOTE: This controller will automatically be released sometime after its view is removed from it' superview...
}
#end
Here is how you might use it in your app delegate:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
//create your root view controller, etc...
UIViewController *rootController = ....
LaunchImageTransitionController *launchImgController = [[[LaunchImageTransitionController alloc] init] autorelease];
[window addSubview:rootController.view];
[window addSubview:launchImgController.view];
[window makeKeyAndVisible];
}
Other than using setAnimationDelay: instead of setAnimationDuration:, it looks pretty good. What don't you like about the results?
Edit: Wow beaten hard.