presentModalViewController translucent with previous view in the background - objective-c

Im trying to present a view translucently and that the previous view sticks around and be that its visible in the background.
I've got
[self presentModalViewController:modalView animation:YES];
and I have the transparency set in the modalView's viewDidLoad, but after modalView gets brought up the previous view disappears. What can I do to keep the other view to stay around in the background?
I have also tried adding it with
[self.view addSubview:modalView.view];
It doesn't cover the whole screen, I would like to be able to solve this problem using presentModalViewController method.

It sounds like you just want a view to be displayed on top of your main view. Modal views are a finicky way of presenting subviews, instead you should look at creating a simple view class to add to your view controller. You can then use [UIView animate...]; method to animate it in and out of view.
To get you started:
- (void)displayViewButtonPressed(id)sender
{
if (!self.topView)
{
UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(44.0f, 22.0f, 40.0f, 44.0f];
[overlayView setAlpha:0.0f];
[overlayView setBackgroundColor:[UIColor redColor]];
[self setTopView:overlayView];
[overlayView release];
}
[self.view addSubView:self.topView];
[UIView animateWithDuration:0.5
animations:^{
[self.topView setAlpha:1.0f];
}];
}
In the above method we create a custom UIView and animate it into position. We maintain a pointer to it so we can remove it later (like so:)
- (void)dismissViewButtonTapped:(id)sender
{
[UIView animateWithDuration:0.5
animations:^{
[self.topview setAlpha:0.0f];
}
completion:^(BOOL finished) {
[self.topView removeFromSuperView];
}
}
Its a little more work that using modal views, but it gives you much more flexibility in regards to what you use and how you display it.
Hope this helps:)

Related

Getting xib dismissed

I have screens: 1st one is xib and 2nd is the controller when I dismiss screen 2. Both screens get dismissed instead of the 2nd controller.
in iOS(Xcode)
if you want remove xib then you just need to removeFromSuperview so only xib will remove.and also please share your code so we can get idea what you did.
[subview removeFromSuperview]
.. and if you want to remove viewcontroller as a subview you need to do
yourViewController.willMove(toParentViewController: nil)
yourViewController.view.removeFromSuperview()
yourViewController.removeFromParentViewController()
1) refer this link for more info 2)Link2
You should Animation with two views.
presentedView.transform = CGAffineTransformTranslate(presentedView.transform, 0, DEVICE_HEIGHT);
[UIView animateWithDuration:0.6f delay:0 usingSpringWithDamping:1 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
presentedView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
appDelegate.window.rootViewController = appDelegate.welcomeViewctrl;
}];

UIView not animating constraint change

I have a question regarding the UIView method:
+ (void)animateWithDuration:(NSTimeInterval)duration
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion
Basically I am just trying to set a height constraints constant to 0 and have the change look like its slowly shrinking...
My Code looks like this:
[UIView animateWithDuration:0.7
animations:^{
//hide the Title
self.titleCellHeigthConstraint.constant = kLabelHeightZero;
[self.contentView layoutIfNeeded];
}
completion:nil];
Unfortunately it's not animating. It simply makes all changes appear with a little delay (which might be the 0.7 seconds specified in the method).
Now my question is if there is any way to get the UIView to animate the change?
Thanks in Advance!
Edit:
The weird thing is if I reverse the changes in an animated fashion it does it exactly the way I want it. The code I'am using for that is:
//animate layout changes
[UIView animateWithDuration:0.7
animations:^{
//hide activity indicator and label
[self.activityIndicator stopAnimating];
[self.label setHidden:YES];
}
completion:^(BOOL arg0){
[UIView animateWithDuration:0.3
animations:^{
//show title label
self.titleCellHeigthConstraint.constant = kDefaultLabelHeight;
[self.contentView layoutIfNeeded];
}];
}];
You want to change the properties of the UIView not the NSLayoutConstraint in the animation method. I.e. Change the layout constraint's constant before the UIView method and then change the UIView's frame property in the animation method.
This way you won't need to call layoutIfNeeded.

PresentViewController with custom “scale-from-center” ModalTransitionStyle

I'm trying to implement custom view presenting transition style. Here is my code:
[myViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentViewController:myViewController animated:YES completion:^(void){}];
I'd like to achieve “scale from center” effect while presenting views. I made a demo of desired effect with JQuery UI: http://jsfiddle.net/c7ztP/
Is there any way to do this?
What I would do is the following
From the initiating view controller i would do this
// OriginalViewController.h
newViewcontroller.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.0f, 0.0f);
[self presentViewController:newViewController animated:NO completion:nil];
And on the receiving view controller I would do this
-(void)viewDidLoad {
[UIView animateWithDuration:0.3f animations:^{
self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0f, 1,0f);
}];
}
For this to work you'll need QuartzCore.framework. Also to make it sweeter I would add zero alpha to full alpha animated as it looks better.
You should write your own Controller with this animation effect.
Look at this controls: KGModal and UAModalPanel.
Check theirs source code for animation example. It's not difficult to rewrite this code to support fullscreen view.

Simple UIView animation move doesn't work

I have no idea, why it is not working.
All I want to do is a simple UIView animation in the viewDidLoad.
Here's my code:
[UIView animateWithDuration:3.0f animations:^{
[self.headline setCenter:CGPointMake(0.0, 200.0)];
}];
Nothing happens. When I test the general approach of calling a animation method on that particular object like this:
[UIView animateWithDuration:3.0f animations:^{
[self.headline setAlpha:0.0];
}];
it works!!! Why am I not able to move the view across the screen? I am using latest Xcode 4.5.
Thanks for any advice!
UPDATE:
When I add a view manually in code it works. But for the UIViews I create as Outlets in the Interface Builder it doesn't work.
UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 100.0)];
testLabel.backgroundColor = [UIColor redColor];
[self.view addSubview:testLabel];
[UIView animateWithDuration:3.0 animations:^{
testLabel.center = CGPointMake(0.0, 200);
}];
So obviously I am doing something wrong in the .xib file
Dont do it in viewDidLoad. The view is not pressent at that time yet.
Try it in viewDidAppear.
Well, I think the reason for the missing animation was the fact that I called a different push navigation animation from the view controller that was pushing the actual view on screen:
- (IBAction)goForSelection:(id)sender
{
SelectionViewController *selectionViewController = [[SelectionViewController alloc] initWithNibName:#"SelectionViewController" bundle:nil];
//[self.navigationController pushViewController:selectionViewController animated:YES];
[UIView transitionWithView:self.navigationController.view duration:1.0 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
[self.navigationController pushViewController:selectionViewController animated:NO];
} completion:^(BOOL finished) {
[selectionViewController startIntroAnimation];
}];
}
First I checked what happens when I use the default navigation controller segue. And to my surprise the animation did start. Then I inserted the call to the [selectionViewController startIntroAnimation] to the completion block and this works as well.

remove every type of subview from uiscrollview?

hello all i am using this code to show flip animation...... i have a uiview with scrollview(paging enabled)...so it shows a view like a page...now i also have done flip animation using this code....
-(void)flipView
{
flashCardAnswerController *flashCardAnswerControllerobj = [[flashCardAnswerController alloc] initWithNibName:#"FlashCardAnswerView" bundle:[NSBundle mainBundle]];
[flashCardAnswerControllerobj.view setFrame:[[self view] frame]];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.60];// Sub. duration
UIView *superview;
if ((superview = [[self view] superview])) {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:superview cache:YES];
[superview addSubview:[flashCardAnswerControllerobj view]];
}
[UIView commitAnimations];
}
so according to code the new view will be added to scrollview..i also manage to release the new view while flipping back...but if i directly push the back button on navigaion controller...the flip side view won't release. i tried this in dealloc method of my scrolleview's class but it doesn't work
for(UIView *subview in [scrollView subviews]) {
[subview removeFromSuperview];
}
how do i remove flipside's view the views are very much in number...approx. 48 plus 48 flip side views so definietly it will create memory issues on device...
also could someone tell me a way to disable NavigationBar's back button in flip side view...without creating scolling class's object.
I do not have a direct answer to your question, but I can tell that this is the old iPhone OS 2.x way of displaying a views flip-side.
In iPhone OS 3.0 you should use presentModalViewController:animated: instead. This is much less code, and all of the problems you describe in your questions goes away.
The idea is that the flip-side of the current view, is managed by a separate UIViewController that you display modally. But in addition to the sliding animation from 2.0 you can also have the new view controller animate in and out with a horizontal flip.
self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:flipSideController
animated:YES];
[[scrollView subviews] makeObjectsPerformSelector:#selector(removeFromSuperview)]