Animate Change View in new IOS - ios5

i cant seem to figure out how to change the views using animation in the new ios 5. i have this code which just switches the views but without any type of animation. This is the code i have so far:
-(IBAction)back:(id)sender{
if ([self respondsToSelector:#selector(dismissViewControllerAnimated:completion:)])
{
NSLog(#"didTouchDoneButton 5.x");
[self dismissViewControllerAnimated:NO completion:nil];
}
else
{
NSLog(#"didTouchDoneButton 4.x");
[self dismissModalViewControllerAnimated:NO];
}
}

When you use presentModalViewController:animated you can change the animation with the method [myModalViewController setModalTransitionStyle: UIModalTransitionStylePartialCurl.

Related

Presenting a view controller turns iPhone's orientation to portrait

I am presenting a view controller that plays video in it.
When I tap to a button, the video player view is initiated from storyboard with this code:
_moviePlayer = [self.storyboard instantiateViewControllerWithIdentifier:#"videoPlayerController"];
[_moviePlayer.view setFrame:self.view.bounds];
[_moviePlayer playMoviesForItems:shopItems];
[self presentViewController:_moviePlayer animated:NO completion:^{
[self.scrollView scrollRectToVisible:CGRectZero animated:YES];
}];
But orientation turns to portrait like this:
I wrote code below but doesn't work:
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation
{
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
There is no problem with iPad. Problem is with iPhone.
Updated:
Supported Orientations are:
Where am I wrong?
Try applying transform and scaling it
CGAffineTransform aTransform =CGAffineTransformMakeRotation(M_PI_2);
currentTransform= CGAffineTransformConcat(aTransform, CGAffineTransformMakeScale(2.0, 2.0));
Use preferredInterfaceOrientationForPresentation method.Hope it will help.
Please put below method as well..My be this will help you
- (BOOL)shouldAutorotate {
return YES;
}

Dismissing camera view crashes app

When I try to dismiss my UIImagePickerController, it crashes the app. the error is: "Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'"
I have the preferred interface orientation set in my view controller.
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
- (BOOL) shouldAutorotate {
return YES;
}
Here is the method I'm calling to bring up the camera, this works fine for adding the camera, but like I said, crashes when I try to remove the camera.
-(IBAction)addCamera:(id)sender
{
self.cameraController = [[UIImagePickerController alloc] init];
self.cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
self.cameraController.cameraViewTransform = CGAffineTransformScale(self.cameraController.cameraViewTransform,
1.13f,
1.13f);
self.cameraController.showsCameraControls = NO;
self.cameraController.navigationBarHidden = YES;
self.wantsFullScreenLayout = YES;
ar_overlayView = [[UIView alloc] initWithFrame:CGRectZero];
self.view = ar_overlayView;
[self.cameraController setCameraOverlayView:ar_overlayView];
[self presentViewController:cameraController animated:NO completion:nil];
[ar_overlayView setFrame:self.cameraController.view.bounds];
}
-(IBAction)back:(id)sender
{
[ar_overlayView removeFromSuperview];
[cameraController dismissViewControllerAnimated:NO completion:nil];
}
Alright, found the solution, it was really simple, I just changed my back method to:
[self dismissModalViewControllerAnimated:YES];
Now my camera goes away and I can see my original view when I press the back button.
I still haven't figured out what was causing the original problem as I've gone through the info.plist and the methods for supported orientations, but this accomplishes what I wanted.
I'm still curious as to what was causing the error though if anyone has any ideas.
You can try remove this method:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
It will fix it.but sometimes it will lead to reduce stateBar height.
You cannot remove a UIViewController's main view from its superview.
Instead of this:
self.view = ar_overlayView;
Try this:
[self.view addSubview:ar_overlayView];
Then you will be able to remove it from the superview correctly.
You should be using the didFinishPickingMedieWithInfo method similar to below and use [self dismissModalViewControllerAnimated:YES];
-(void) imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
NSLog(#"Camera");
}
else {
NSLog(#"Album");
}
[self dismissModalViewControllerAnimated:YES];
}
I don't think you need to add ar_overlayView to the current view yourself if it's a camera overlay.
Here's what your code is doing now:
Add ar_overlayView to the current view
Add ar_overlayView as the camera's overlay view
Show the camera view (modal)
At this point, ar_overlayView is being displayed twice. When you send it the removeFromSuperview message on dismissing the camera view, it might be getting confused since it's in two view hierarchies at the same time.
Skipping the self.view = ar_overlayView; or [self.view addSubview:ar_overlayView]; lines should fix the problem.
Also, dismissViewControllerAnimated:completion: should be sent to the same object that presentViewController:animated:completion was called on (self in this case):
-(IBAction)addCamera:(id)sender
{
// -- snip -- //
ar_overlayView = [[UIView alloc] initWithFrame:self.cameraController.view.bounds];
[self.cameraController setCameraOverlayView:ar_overlayView];
[self presentViewController:self.cameraController animated:NO completion:nil];
}
-(IBAction)back:(id)sender
{
[self dismissViewControllerAnimated:NO completion:nil];
}

Strange warning dismissing modal view controller

I'm working on iOS 6.
My application has a standard navigation controller with embedded a CustomViewController.
In this controller I create a modal view like this:
-(IBAction)presentModalList:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
StationsListViewController *list = [storyboard instantiateViewControllerWithIdentifier:#"StationsListViewController"];
[list setStationsData: [self.stationsData allValues]];
[self presentModalViewController:list animated:YES];
}
The modal controller show perfectly but dismissing generates a warning.
The dismiss method in this controller is:
-(IBAction)backToMap
{
[self dismissModalViewControllerAnimated:YES];
}
The warning generated is Warning:
Attempt to dismiss from view controller < UINavigationController: 0x1ed91620 > while a presentation or dismiss is in progress!
Any clues about that?
Thanks
I realise this is a late answer but maybe this will help someone else looking for a solution to this, here is what I did:
-(IBAction)backToMap
{
if (![[self modalViewController] isBeingDismissed])
[self dismissModalViewControllerAnimated:YES];
}
For me, i found that line of code was being called multiple times, I couldn't find out why so this was the easiest fix.
Thanks JDx for getting me on the right track. I adapted it to form this solution, which will remove the warning without using functions that are deprecated in iOS 6:
-(IBAction)backToMap
{
if (![self.presentedViewController isBeingDismissed]) {
[self dismissViewControllerAnimated:YES completion:^{}];
}
}
Targeting iOS6, this is what worked for me:
if (![self.presentedViewController isBeingDismissed])
[self.presentedViewController dismissViewControllerAnimated:YES
completion:nil];
I found this approach to be unreliable - say one case in five I'd still see the error.
My solution was to use the completion block to set a flag which controls whether or not it's safe to dismiss - that way you don't need to check whether or not the view is being dismissed.
-(IBAction)presentModalView:(id)sender {
:
self.canDismiss = NO;
[self presentViewController:aVC animated:YES completion:^{
self.canDismiss = YES;
}];
:
}
In the bit of code where the dismiss occurs, just check the flag:
-(void)dismisser {
:
if (self.canDismiss) {
[self dismissViewControllerAnimated:YES completion:nil];
}
:
}
Hey presto, no more errors!
You can do whatever you want after the completion of the dismiss method as:
-(IBAction)backToMap
{
[self dismissViewControllerAnimated:YES
completion:^{
//Do something here
}];
}

isBeingDismissed not set in viewWillDisappear:

I have some code to clean up in my viewWillDisappear:, which I only want to use when the view is moving back to the parent view controller.
- (void)viewWillDisappear:(BOOL)animated
{
if ([self isMovingFromParentViewController] || [self isBeingDismissed]) {
NSLog(#"isMovingFromParentViewController or isBeingDismissed");
// clean up
}
[super viewWillDisappear:animated];
}
The view can be presented in two ways: it can be pushed by a navigation controller, or presented as a modal view controller (from the same navigation controller). If it's pushed, then popped (pressing the back button), my clean-up code runs. If it it presented as a modal view controller, then dismissed, the code doesn't run.
I dismiss like so:
[rootViewController dismissModalViewControllerAnimated:YES];
My question is: why isn't isBeingDismissed set when I dismiss my view controller?
If this is the first view controller in a modal navigation controller that's being dismissed, calling self.isBeingDimissed() from viewWillDisappear: returns false.
However, since the entire navigation controller is being dismissed, what actually works is self.navigationController?.isBeingDismissed(), which returns true.
As #Yuval Tal mentioned, this flag does not work when you're dismissing controller that is embeded inside navigation controller. Here's an extension that I use:
extension UIViewController
{
var isAboutToClose: Bool {
return self.isBeingDismissed ||
self.isMovingFromParent ||
self.navigationController?.isBeingDismissed ?? false
}
}
It can be easily extended when you find another case when standard .isBeingDismissed won't work. And if you find, let us, let me know in comments.
Your issue is how you are dismissing your modal view. How is rootViewController being defined?
When I call [self dismissModalViewControllerAnimated:YES] then [self isBeingDismissed] evaluates to true.
When I call [parentViewController dismissModalViewControllerAnimated:YES] then [self isBeingDismissed] evaluates to true, whereby parentViewController is the UIViewController that presented the modal view (note: not a UINavigationController).
If by some chance you came here trying to use isBeingDismissed on a non-modally presented view controller, you can always check the topViewController property of your navigationController, for instance:
if navigationController?.topViewController != self {
return
}
viewController.isBeingPresented == NO;
[rootVC presentViewController:viewController animated:NO completion:^{
viewController.isBeingPresented == NO;
viewController.isBeingDismissed == NO;
[viewController dismissViewControllerAnimated:NO completion:^{
viewController.isBeingDismissed == NO;
}];
viewController.isBeingDismissed == NO; // is not work
}];
viewController.isBeingPresented == YES; // is work
viewController.isBeingPresented == NO;
[rootVC presentViewController:viewController animated:NO completion:^{
viewController.isBeingPresented == NO;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
viewController.isBeingDismissed == NO;
[viewController dismissViewControllerAnimated:NO completion:^{
viewController.isBeingDismissed == NO;
}];
viewController.isBeingDismissed == YES; // is work
});
}];
viewController.isBeingPresented == YES; // is work

Unload a flipview

I need to fully UNLOAD the flipview don't ask me why but i NEED to. i have tried [super release]; and it didnt work below is my back button and then the did finish. Please help me to unload the view.
on the first view which gets activated once the flipview has finished.
- (void)flipViewControllerDidFinish:(FlipViewController *)controller
{
[self dismissModalViewControllerAnimated:YES];
}
on the flip view which is a button that hides the flip view just hides doesn't unload
- (IBAction)Back:(id)sender
{
[self.delegate flipViewControllerDidFinish:self];
}
[myFlipViewController.view removeFromSuperview];