I am trying to use a custom transition. I want a "cover vertical" transition from View Controller 1 to 2 and then have View Controller 2 (the middle one) slide back down again when moving to View Controller 3. Storyboard shown below:
http://i.stack.imgur.com/bJYXI.png
Im using the tutorial that is linked to from this post. And have also replaced the .m code with the code provided in the answer:
Xcode custom segue - Opposite of Cover Vertical (top to bottom) - COMPLETE NEWBIE
I have created a subclass of UIViewController and named it FromTopReplaceSegue. My .h and .m code is shown below:
.h
#import <UIKit/UIKit.h>
#interface FromTopReplaceSegue : UIViewController
#property(nonatomic, readonly) id sourceViewController;
#property(nonatomic, readonly) id destinationViewController;
#end
.m
#import "FromTopReplaceSegue.h"
#interface FromTopReplaceSegue ()
#end
#implementation FromTopReplaceSegue
-(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:CGAffineTransformMakeTranslation(0, -sourceViewController.view.frame.size.height)];
[destinationViewController.view setAlpha:1.0];
[UIView animateWithDuration:0.75
delay:0.0
options:UIViewAnimationOptionTransitionFlipFromTop
animations:^{
[destinationViewController.view setTransform:CGAffineTransformMakeTranslation(0, 0)];
[destinationViewController.view setAlpha:1.0];
}
completion:^(BOOL finished){
[destinationViewController.view removeFromSuperview];
[sourceViewController presentViewController:destinationViewController animated:NO completion:nil];
}];}
#end
When i try to run the simulator i can easily get from Controller View 1 to 2 but it crashes when i try to move from Controller view 2 to 3 using the custom segue.
Can anyone help.
Thank you so much in advance! Struggling here! :)
Some time gone since my iOS days, but shouldn't the .h not define a subclass of a seque class instead of a viewcontroller? Like
#interface FromTopReplaceSegue : UIStoryboardSegue
You can read its documentation for some notes on subclassing as well...
Related
I've searched and searched for the answer to this issue and the solutions i've found doesn't seem to work, so I guess i'm doing something wrong: i want to call this method
-(void)customFade:(UILabel *)theLabel withDelay:(float)delayAmount {
[UIView animateWithDuration:0.5
delay:delayAmount
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[theLabel setAlpha:1.0f];
[theLabel setAlpha:0];
}completion:nil];
}
from a VC called View Controller to another but it isn't being recognized despite the imports... here's what i'm trying on the desired VC:
- (void)viewDidLoad {
[super viewDidLoad];
ViewController *ViewController = [[ViewController alloc] init];
[ViewController customFade:_label withDelay:0.3];
}
the warning says "no visible #interface for "ViewController" declares the selector alloc
Can someone help me out? I'm kind of new at this, thank you
such an error usually happens when you have mistyped the name of the method, or that method doesn't belong to that class at all and doesn't exist in your class.
and ensure once your VC is subclass with UIViewController
#interface ViewController : UIViewController
change your instance object type and check once
ViewController *vc = [[ViewController alloc] init];
[vc customFade:_label withDelay:0.3];
and change the animation like
[UIView animateWithDuration:0.5
delay:delayAmount
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[theLabel setAlpha:1.0f];
}completion:{
[theLabel setAlpha:0];
}];
for more information you can get the reference from here
When I am creating a custom segue from one view controller to another, there's a problem with showing top bar properly.
This is the code for custom segue:
#implementation CustomSegue
- (void)perform {
UIViewController *sourceViewController = self.sourceViewController;
UIViewController *destinationViewController = self.destinationViewController;
[sourceViewController.view addSubview:destinationViewController.view];
destinationViewController.view.alpha = 0.0;
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
destinationViewController.view.alpha = 1.0;
}
completion:^(BOOL finished){
[sourceViewController presentViewController:destinationViewController animated:NO completion:NULL];
[destinationViewController.view removeFromSuperview];
}];
}
#end
I am using storyboard to set this up and sourceViewCotoller is embeded in NavigationViewController.
After performing a segue, there is no top bar in th destinationViewController.
I found an answer that I should add a Navigation Item to the destinationViewController - doesn't help.
Another way of dealing with this that I found is embedding the destinationViewController in NavigationViewController.
After doing this, the top bar is visible, but also during the segue.
It's probably because I am adding the desitnationViewController into sourceViewController, so at the beginning of segue I have 2 top bars visible one below another.
How to deal with this ?
SET UP
In my view controller i have a View and 2 Buttons
everything positioned in a Storyboard, and linked to ViewController.h
STEP 1 : I push the 1st button to make the View move.
STEP 2 : I push the 2nd button to pop the UIActionSheet.
PROBLEM
As soon as I push the 2nd button, my View position comes back as defined in the storyboard.
Here is my code :
ViewController.h
#interface ViewController : UIViewController<UIActionSheetDelegate>
#property (strong, nonatomic) IBOutlet UIView *view1;
- (IBAction)move:(id)sender;
- (IBAction)bringPop:(id)sender;
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
//move _View1
- (IBAction)move:(id)sender {
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
_view1.layer.frame= CGRectMake(0, 79, 320, 489);
} completion:nil];
}
//action sheet pops
- (IBAction)bringPop:(id)sender {
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:#"" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:#"0" otherButtonTitles:#"1", #"2", #"3", nil];
[popupQuery showInView:self.view];
}
#end
You might need to overwrite the method
-(void)layoutSubviews
This method should be overwritten when the AutoLayout or AutoResizingMasks doesn't perform the layout that you require. I'm pretty sure that the UIActionSheet presents itself as a modalViewController which triggers a viewDidAppear and viewWillAppear in your actual ViewController.
Try setting some break points and check if this methods are triggered if so then AutoLayout or AutoResizingMasks are resetting your frames as in the xib file.
It will depend a lot on how are you building your views
You're setting the view's layer's frame, rather than just the view's frame
The animation block should be
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
_view1.frame= CGRectMake(0, 79, 320, 489);
} completion:nil];
I am trying to implement a flip between two view controllers embedded into a container view. In the real app, the flip button swaps between a map and a list.
In this mockup of the problem, the Coffee UITableViewController is swapped out for the Sweets UIViewController.
It works fine in the simple case, but when I add a segue to the Sweets Controller to go to a child UIViewController, things go awry after the following actions - Flip - segue - Back - Flip. Repeat those actions and the tableview slowly makes its way down off the screen.
The code in FlipViewController is:
#interface FlipViewController ()
#property (strong, nonatomic) UIViewController *controller1;
#property (strong, nonatomic) UIViewController *controller2;
#property (strong, nonatomic) UIViewController *currentViewController;
#end
#implementation FlipViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.controller1 = [self.childViewControllers firstObject];
self.currentViewController = self.controller1;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
self.controller2 = [storyboard instantiateViewControllerWithIdentifier:#"Sweets Controller"];
[self addChildViewController:self.controller2];
}
- (IBAction)flip:(id)sender {
if (self.currentViewController == self.controller1) {
[self transitionFromViewController:self.controller1 toViewController:self.controller2 duration:0.3 options:UIViewAnimationOptionTransitionFlipFromRight animations:nil completion:^(BOOL finished) {
[self.controller2 didMoveToParentViewController:self];
self.currentViewController = self.controller2;
}];
}
else {
[self transitionFromViewController:self.controller2 toViewController:self.controller1 duration:0.3 options:UIViewAnimationOptionTransitionFlipFromRight animations:nil completion:^(BOOL finished) {
[self.controller2 didMoveToParentViewController:self];
self.currentViewController = self.controller1;
}];
}
}
#end
Some debugging seems to indicate the bounds of the UITableView is getting confused upon return. Do I have an AutoLayout problem or is my approach with transitionFromViewController: the wrong way to go about getting this effect? Any suggestions would be appreciated, I've been stuck on this bug for too long!?
hi i'm trying to create a custom modal segue that slides the src view controller to right which reveals destination view controller behind it. any ideas on how i can acheive it
so far i have tried this but it's not working.
#import "CustomMenuSegue.h"
#implementation CustomMenuSegue
- (void) perform {
UIViewController *src = (UIViewController *) self.sourceViewController;
UIViewController *dst = (UIViewController *) self.destinationViewController;
[UIView transitionWithView:src.navigationController.view duration:0.2 options:UIUserInterfaceLayoutDirectionRightToLeft
animations:^{
[src.navigationController modalTransitionStyle:dst animated:YES];
}
completion:NULL];
}
#end