Modal view at right half of ipad's screen? - ios

I need to modify a view's modal presentation with this parameters:
1 - Modal view only fills the ipad's right half of the screen.
2 - The animation runs from the left half of the screen.
I have search in iosframeworks.com, cocoacontrols.com, the books from big nerd rach, ios recipes, ios pushing the limits, stackoverflow and google. Is some posibility to do that?
Thanks for your assistance
For testing, after two days of searching answers, I create the following code, I'm executing the following code since the root view controller CMMainView, the viewcontroller CMVistaModal is empty, its doesn't have any overrided method nor xib nor another variable, the device family is iPad
-(IBAction)accion:(id)sender
{
CMVistaModal *modal = [[CMVistaModal alloc] init];
[modal setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentViewController:modal animated:NO completion:nil];
[modal.view.superview setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[modal.view.superview setFrame:CGRectMake(800, 120, 200, 500)];
[UIView animateWithDuration:1 animations:^{
modal.view.superview.transform = CGAffineTransformMakeTranslation(-200, 0);
}];
}
how can i perform the same operation but overriding the methods from CMVistaModal?

Absolutely. Just make a new view and add it to your existing view and animate it into position. You can have another view appear behind it blocking any touches to other views.

Anything is possible. It just depends on how much work you wish to put in.
So a standard UIModalPresentationFormSheet or UIModalPresentationPageSheet comes for free. But what you want isn't standard so you have to bake your own.
What I would do here is create a "fake" modal.
With
XYViewController -> Container View
Container View -> Semi Opaque blocker
-> Half Screen Content
The blocker covers the entire screen and goes in immediately and prevents interaction with the rest of the UI
Then animate the "Half Screen Content" in from the left with a standard frame animate. How you choose to dismiss this fake modal is up to you but if it comes in from left perhaps it should depart to the left.

Related

presentViewController working in iOS 6 but not displaying the view in iOS 5

I started developing my app for iOS 6 and got it working there, now I am having to make sure it also supports iOS 5.1 so it will work on the iPad 1. The port was pretty easy, though only supporting landscape orientation is more of a pain in iOS 5 compared to how easy it is in 6. I'm left with one issue that I can't resolve.
I have the starting screen layout shown below and then when you press the 'Perform' button it should present another view controller modally, full screen. This is the code that the perform button calls in the parent view controller.
- (void)performButtonPressed:(UIImage *)notationImage {
self.performViewController = [[YHPerformViewController alloc] initWithImage:notationImage
recordingService:self.performanceRecordingService];
self.performViewController.modalPresentationStyle = UIModalPresentationFullScreen;
self.performViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:self.performViewController animated:YES completion:^{
[self.performViewController startPerformance];
}];
}
In iOS 6 this is fine. In iOS 5 all the right code seems to be called:
loadView on the view controller being presented
shouldAutorotateToInterfaceOrientation - to which I return YES
my 'startPerformance' method is called and does its things
However the view doesn't actually appear on screen and all the views associated with view controllers higher up the hierarchy stay on screen (the shapes at the top and the navigation control). Only the view for the current view controller is faded out. Even weirder is that during the transition this view is rotated 90 degrees as it is fading out. I've included a screen capture below. If I change the modalPresentationStyle to UIModalPresentationFormSheet it kind of works apart from the expected issue of my full sized view not fitting.
Any thoughts?
Starting layout:
Weird rotation of subview during transition. Also the whole screen should be fading out, not just one view:
What was expected to happen and does in iOS 6.
I have come up with a hack that solves this problem. But I would love to find a real solution.
My bodged solution is to change the modalPresentationStyle to UIModalPresentationFormSheet. Then use a variation on the hack described in How to resize a UIModalPresentationFormSheet? to get the form sheet to be the desired size.
- (void)performButtonPressed:(UIImage *)notationImage {
self.performViewController = [[YHPerformViewController alloc] initWithImage:notationImage
recordingService:self.performanceRecordingService];
// This is a bit of a hack. We really want a full screen presentation, but this isn't working under iOS 5.
// Therefore we are using a form sheet presentation and then forcing it to the right size.
self.performViewController.modalPresentationStyle = UIModalPresentationFormSheet;
self.performViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:self.performViewController animated:YES completion:^{
[self.performViewController startPerformance];
}];
self.performViewController.view.superview.bounds = self.performViewController.preferredBounds;
}
This requires the view controller being presented to a 'preferredBounds' property and to have this in its loadView method.
- (void)loadView {
… // Usual loadView contents
// Part of the hack to have this view display sized correctly when it is presented as a form sheet
self.preferredBounds = self.view.bounds;
}
[self presentViewController:self.performViewController animated:YES completion:nil] works in iOS 6+ versions only.
You have to use [self presentModalViewController:controller animated:YES]; in

Advert layout incorrectly opening from modal

I've taken over development of an iPad app and am adding AdMob into it, this is all working correctly apart from one layout issue when the advert opens, I believe it may be to do with it opening from a modal window.
The advert opens with some content from the previous window infront of it, it covers the status bar, and leaves a space at the bottom about the same height as the status bar. I'm adding this advert in the same way I am the others, which work from...
GADAdSize customAdSize = GADAdSizeFromCGSize(CGSizeMake(300, 50));
adView = [[DFPBannerView alloc] initWithAdSize:customAdSize];
adView.adUnitID = #"xxxxxxxxxxxx";
adView.rootViewController = self;
[self.view addSubview:adView];
[adView setDelegate: self];
Any ideas how this can be fixed, without restructuring the app so the previous one isn't a modal window?
Are you hiding the status bar before you display the initial modal view? I know the click through modal for AdMob usually gets off-place if you do this.
Make sure you're also not doing anything else weird with positioning when you display your first modal.

pushViewController with scaling animation, that shows background

I have finding way to call pushViewController with scaling animation,
like facebook iPhone app main menu icon click animation.
(new viewController is popup from center, and it scales to original size.)
I searched several way to change animation of pushViewController.
First, I tried this:
viewController.view.transform = CGAffineTransformMakeScale(0.5f, 0.5f);
[UIView animateWithDuration:0.5f animations:^{
viewController.view.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
}];
[self.navigationController pushViewController:viewController animated:NO];
but there is problem,
old viewController is disappeared when animation starts, there's only white background.
If I use CATransition to change animation,
I can show both old & new viewController both,
but there's no scaling animation, only move in, push in, fade in animations.
I want to show both new & old view controller like CATransition animations,
and need the way to implement my custom animation.
Here is my last suggestion, dirty way:
[self.view addSubview:viewController.view];
viewController.view.transform = CGAffineTransformMakeScale(0.5f, 0.5f);
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveEaseInOut
animations:^{
viewController.view.alpha = 1.0f;
viewController.view.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
} completion:^(BOOL finished) {
[self.navigationController pushViewController:viewController animated:NO];
[viewController release];
}];
First, I added new viewController.view as subview, I can show animation with new & old view both.
When animation is ended, pushViewController later.
this way I can implement what I thought,
but I think it is dirty way, and there's remain problem:
Navigation bar items are not change immediately, It is changed after animation ends.
Is there any simple, clear way to implement this animation?
I think it is impossible to do that without change original implentation of pushViewController, should I do subclassing pushViewController?
Thanks to read, and your help.
In answer to the original question, I'm not sure if you consider this an improvement or not, but I think you might be able to include the navigator bar in the view that's being transformed (a) in IB, add a navigationBar to your view being transitioned to, (b) animate the hiding of the root navigation controller's navigation bar before you start your animation (so it slides off as your new view is sliding in), and (c) in your completion block of your animation, hide your new view's added navigation bar and unhide the root navigation controller's navigation bar. Maybe this renders something closer to what you intended, though probably different than you originally conceived. It's not perfect, though. The code, might look something like:
MyViewController *newController = [[MyViewController alloc] initWithNibName:#"MyView" bundle:nil];
newController.view.transform = CGAffineTransformMakeScale(0.1f, 0.1f);
[self.navigationController setNavigationBarHidden:YES animated:YES];
[self.view addSubview:newController.view];
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveEaseInOut
animations:^{
newController.view.alpha = 1.0f;
newController.view.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
} completion:^(BOOL finished) {
[newController.view removeFromSuperview];
[self.navigationController pushViewController:newController animated:NO];
[newController.tempBar setHidden:YES];
[self.navigationController setNavigationBarHidden:NO animated:NO];
}];
It's adding a little more "dirt" to your "dirty way", but it might render the effect that you're looking for. You just want to make the temporary navigation bar in your new view to look as much like what the eventual root navigation controller's navigation bar will look like, and the user should be none the wiser. If this still doesn't quite achieve what you're looking for, you can just hide the root navigation controller's bar altogether, and always put your navigation on your views themselves, in which case the effect will be entirely seamless as you transition to your new view.
Alternatively, you could stay with your existing code and just set the title of the current view before you transition, that way it might look like the title change happened up front. But then you probably have to do stuff about resetting it when you return, setting the back button, etc., so it might not be worth it.
As an aside, and this is a little tangential to the original question (so I apologize in advance), but in response to the other suggestion that you shouldn't animate the view controller, but rather only views, I would like to voice a word of caution. Yes, technically that's right, but I'm nervous whether this will encourage people to adopt the bad practice of adding new views by (a) creating a new view controller; (b) animate the adding of that view controller's view to be a subview of the current view; but (c) not doing anything with that new view controller to add it to your view controller hierarchy (such as pushViewController or presentViewController).
If that's what was intended to the other answer, I have to say that I think this is a very bad idea. (If that's not what was intended, then my apologies, but I think it's easy for people to misconstrue the suggestion.) Bottom line, I have recently seen people do things like:
MyViewController *newController = [[MyViewController alloc] initWithNibName:#"MyView" bundle:nil];
// do some animation around adding the new view as a subview of your current view
// but neglect to ever invoke pushViewController or presentViewController
[self.view addSubview:newController.view];
This is not recommended for a couple of reasons. First, if it's an ARC project, your view controller will be discarded when newController falls out of scope. (There seem to be a spate of these sorts of questions being posted on SO resulting from exceptions being thrown as people transition to ARC.) Sure, you can fix this by making newController an ivar of your main controller so it won't fall out of scope, but be careful to remember to set it to nil when the main controller is eventually dealloc'ed or as you remove your subview, or else you can get a leak. And if you're in a non-ARC project, it's even easier to leak, so make sure to release the view controller when the subview is removed to prevent leaks.
Second, and probably more importantly, while the above code seems to work (or at least if you make the controller an ivar), but you end up with a disconnect between your hierarchy of your view controllers and that of your views. (In session 102 of WWDC 2011 about a different topic, view controller containment, it includes a lengthy, yet relevant, discussion of the importance of keeping view controller hierarchies and view hierarchies coordinated, e.g. rotation events may not be properly sent to your new view's controller because the controller isn't in the controller hierarchy, so iOS won't know to send them to your controller.) Bottom line, if you use another view controller's view to add as a subview of your current view, it is fragile, is susceptible to breaking on iOS upgrades, and things like rotation events will not be passed to your new view's view controller properly. If you do so, at least be aware that this is not good practice and make your own risk-assessment as to whether you want to do that. It's not necessary to bypass the proper view controller hierarchy, and I personally would like to dissuade people inclined to do so.
Bottom line, if you're transitioning to a view of a different view controller, you really want to stick to pushViewController or presentViewController, and do your animation around the new controller's view (and usually it's nowhere near as complicated as this animation ... generally it's incredibly simple and I've done all sorts of fade and flip animations with much greater ease ... it's the use of the transform that is making this complicated).
Alternative, if you want to animate a new UIView subview and not deal with view controllers at all, just make sure it's not another view controller's view, but rather, for example, a view you create programmatically that uses the same view controller as your originating view. And if you decide to use another view controller's view as a subview of your existing controller, just do so with the knowledge that it's a little fragile and some events may not be transmitted to your new view controller as you expect and it might not be as "future proof" as you may want.
I don't think that animation is done with a view controller. You can just keep the existing view controller. Create a new UIView that is supposed to zoom in. Add that new UIView to the existing view controller and apply animation to it.

ipad page/form modal view's are no longer transparent in 4.2.1

In my app I have been using page and form modal view controllers like the following:
quickTemplateViewer.modalPresentationStyle = UIModalPresentationPageSheet;
quickTemplateViewer.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[parent presentModalViewController:myView animated:YES];
I have an offset close button that hangs over the view on the top left (the view is slightly smaller than the designated modal view size), and it has been working well as the background of hte modal view is partially transparent.
I upgraded to 4.2.1 and suddenly instead of a semi-transparent black background with a drop shadow I have a white background with rounded corners. Is there a new setting to turn it back to transparent?
Thanks
I spent all day searching for a solution on this, and eventually gave up and made my own solution.
Basically what I did was instead of loading my 'modal' with presentModalViewController, I just added a full size view with a black backgroundColor that had 80% opacity so that it shows the view underneath a little dimmed.
Inside of this view, I added the view that I usually loaded with presentModalViewController with the appropiate X & Y coordinates. this way, you mimic the behavior of the UIModalPresentationPageSheet: you get a dimmed background, and the user can't use any UIControl that's underneath.
it's probably not the best implementation, but it's the best I could come up with. Hope something similar works for you guys.
-- UPDATE
Mike asked how did I implement the animations that usually come with the modal. Basically, what I used was a UIView animationTransition:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:
UIViewAnimationTransitionFlipFromLeft forView:anotherView cache:YES];
[mainContainer addSubview:modal.view];
[UIView commitAnimations];

iPad Partial Curl modal transition always curls to full screen

I'm using UIModalTransitionStylePartialCurl to show a modal view in iPad.
modalViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[[self parentViewController] presentModalViewController:modalViewController animated:YES];
self is the right side view controller of my SplitViewController.
When I do this, the page is curled all the way to the top even though the size of the view of modalViewController is small. I only need it to curl a little so it would reveal ONLY the area taken by modalViewController. What I'm trying to do is something exactly like the iPad maps application settings.
I tried using all the modalPresentationStyle options for the modal view and I also tried setting the modalPresentationStyle.view.frame to a small CGRect but still couldn't get it to work.
Can anybody help on this...thanks in advance..
Just leave a clean space (No Controls or Images) in the top of your PresentedViewController, the Framework make the rest.
I have yet to find a more optimal solution, but I've been able to get good results by making the modal (revealed) view the same size as the parent (curling) view. iOS looks at the subviews to determine where to stop the curling and shows "just enough" of the subview to keep the subview pieces on-screen.

Resources