UIview animation like Mac OS kernel panic - iphone

When Mac kernel panic, there's animation, it's not like slide animation exactly, how to implement this animation in iPhone, is there a exist API to do this?

There is no API for that but it is fairly simple animation:
Simply create a UIView and animate its frame, changing from 0 height to full height:
// Create your view
UIView *kPview = [[UIView alloc] init];
// Add it to your view
[self.view addSubView:kPview]
// Set its frame
kPview.frame = CGRectMake(0,0,320,0);
//Set the animation
[UIView animateWithDuration:5
animations:^{
kPview.frame = CGRectMake(0,0,320,460);
}
completion:^(BOOL finished){
//add a UILabel with the warning.
}];

Related

scale animation from scroll sub view (Image view ) to UIwindow and zoom

May be this Question may be duplicate but i really need your help..
UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
NewFeedDetailVC *nextViewController = [[NewFeedDetailVC alloc] initWithNibName:#"NewFeedDetailVC" bundle:[NSBundle mainBundle]];
nextViewController.originRect = imgFrame;
nextViewController.currentscrolloffset=aStylizedView.contentOffset.y;
[window addSubview:nextViewController.view];
[UIView animateWithDuration:0.5
animations:^{
nextViewController.view.frame = CGRectMake(0, 20, 320, ScreenHeight-20);
}
completion:^(BOOL finished){
}];
above is demo code i have tried to make zoom animation before push ..
imgFrame is image on which user will tap
When user click right top orange (four square) button ,and code as below
[UIView animateWithDuration:0.5
animations:^{
self.view.frame=self.originRect;
}
completion:^(BOOL finished){
[test removeFromSuperview];
[self.view removeFromSuperview];
}];
view should be pop out with zoom in animation to there parent frame but i am not able to perform smooth transition and image suppose to be same as parent frame and just black view is scaling to original frame, and another issue is you can observe animation is not clipping out in navigation control even if Its frame is clipping in original scroll view.
Thanks

Unable to animate just a frame to slide up on click of a button.

I am try to create an animation in my app which would slide up a frame to my desired position. The frame would be having other buttons and text on it as well.
I was unable to use actionsheet for this, as it starts from the bottom most part of the window. What i want to create is shown in the picture below.
the frame I want to animate is the one with Capture mode: text.
Click on the button on the tabView I want this frame to slide up, starting from the top of the tabview. and again clicking the button should make the frame disappear.
So far my code looks like
-(IBAction)setting
{
NSLog(#"finalShare Button");
UIView *tempView;
CGRect tmpFrame;
tempView = [[[UIView alloc] initWithFrame:CGRectMake(0, 490, 320, 90)]
autorelease];
[tempView setBackgroundColor:[UIColor clearColor]];
[tempView setAlpha:.87];
tempView.hidden = YES;
[self.view addSubview:tempView];
tmpFrame = tempView.frame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.75];
tmpFrame.origin.y=390;
self.view.frame=tmpFrame;
[UIView commitAnimations];
}
The problem I am facing here is that when I animate my frame to move, the main view moves along with it. Which is something I don't want it to do.
I am new to iPhone programming, please guide how can I fix this.
Or what would be a better way to do it.
Thanks
You don't need to make the view hidden, just add it as a subview after you set its frame to have y origin of 480. Also, don't use the old UIView animation methods; use blocks.
Here's an example of a view that starts with a y origin of 0. It gets positioned at negative y equal to its height, added as a subview then animated down to meet the keyboard coming up from the bottom of the screen.
// add to view while completely off-screen
CGRect unlockViewFrame = unlockView.frame;
unlockViewFrame.origin.y = -unlockViewFrame.size.height;
unlockView.frame = unlockViewFrame;
[self.view addSubview:unlockView];
unlockViewFrame.origin.y = 0.;
[UIView animateWithDuration:0.3 animations:^{
unlockView.frame = unlockViewFrame;
}];
Here's the same thing in reverse, using a completion block to remove the view.
unlockViewFrame.origin.y = -unlockViewFrame.size.height;
[UIView animateWithDuration:0.3 animations:^{
view.frame = unlockViewFrame;
} completion:^(BOOL completion) {
[view removeFromSuperview];
}];
Another thing I notice is that you are doing everything in code; consider doing it in Interface Builder. A smart man once told me that code you don't write can't have any bugs and he was right. It's easy to create a view in IB and instantiate it inyour code when you need it:
NSArray* nibViews;
nibViews = [[NSBundle mainBundle] loadNibNamed:#"UnlockView" owner:self options:nil];
UnlockView *unlockView = [nibViews objectAtIndex:0];
Also, consider using ARC. No more autorelease!
Your resetting frame of main view and not tempView
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.75];
tmpFrame.origin.y=390;
tempView.frame=tmpFrame; //it should be tempView not self.view ie main view
[UIView commitAnimations];

Extend view to bottom of superview

I want to animate a view inside ViewController, somewhat like the notification center as seen on the iPhone.
How does one extend the subview using the x,y and/or the height values to do this? Because I would like it to be compatible with both the 3.5 inch screens and the 4 inch screens, so it would be better not to use specific values.
I just tested this out in my own project and confirmed that it works on varying screen sizes.
UIView *slidingview = [[UIView alloc] initWithFrame:CGRectOffset(self.view.frame, 0, -self.view.frame.size.height)];
slidingview.backgroundColor = [UIColor whiteColor];
[self.view addSubview:slidingview];
[UIView animateWithDuration:1 animations:^{
slidingview.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
}];
To implement this, simply replace slidingview with the view you want to slide down. You would, however, have to declare your own view using the frame I provided.
How about something like this?
CGRect currentFrame = self.view.bounds;
UIView * slidingView = [UIView alloc] initWithFrame:(CGRect){currentFrame.origin, currentFrame.size.width, 0};
[self.view addSubview:slidingView];
[UIView animateWithDuration:0.5f animations:^{
slidingView.frame = currentFrame;
}];
You may need to use delay version of animateWithDuration... to make animation in effect.

Fade to black within a uinavigationcontroller?

I want to fade the whole screen (including navigation bar) to black when a user presses a button on a uinavigationcontroler, before showing a new view. (i don't want to push this new view, for various reasons).
How would I achieve this?
EDIT
Thanks to Mac and Eiko, I have figured it out. Here's the code I used. Not sure if it is optimal, but it does the trick.
// this is called from a programmatically constructed button.
// change (void) to (IBAction) if linking from IB.
- (void)fadeAndShow:(id)sender
{
// blackView is a #property which has been #synthesize-d
// do I really need to alloc and init this?
blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
blackView.alpha = 0.0;
[blackView setBackgroundColor:[UIColor blackColor]];
[self.navigationController.navigationBar.superview addSubview:blackView];
[UIView beginAnimations:#"fadeAway" context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDidStopSelector:#selector(showNewScreen:finished:context:)];
blackView.alpha = 1.0;
[UIView commitAnimations];
}
-(void)showNewScreen:(NSString *)animationID finished:(BOOL)finished context:(void *)context
{
// I guess you could fade in somewhere in the new view controller.
// don't know how to fade back in this view tho... viewDidAppear?
NewViewController *controller = [[NewViewController alloc] initWithNibName:#"NewView" bundle:nil];
[self.navigationController setNavigationBarHidden:YES];
controller.hidesBottomBarWhenPushed = YES;
[[self navigationController] pushViewController:controller animated:NO];
[blackView removeFromSuperview];
[controller release];
}
Off the top of my head (I haven't actually tested the following at all):
-(IBAction) buttonClicked:(id) sender
{
[UIView beginAnimations:#"myAnimation" context:nil];
[UIView setAnimationDuration:ANIMATION_DURATION];
blackView.alpha = 1.0;
[UIView commitAnimations];
}
Create a UIView in the navigationbar's superview (which I'm assuming is window-sized) that is the same size as the window.
Set that view's backgroundColor to [UIColor blackColor], and its alpha to 0.0.
In your button handler do something like the above (assuming your new UIView is blackView and ANIMATION_DURATION is your desired animation time in seconds).
Then, add your new view on top.
EDIT: too quick for me Eiko! Also, code at the top since the ordered list seems to screw around with the code formatting - sorry the answer reads a little odd.
You can add a black coloured UIView in screen size on top of your current view, and animate its alpha from 0 to 1. When the animation is done, add your new view. You can remove the black one then. Animate from 1 to 0 for the opposite effect - going from black to the content).

iPhone - flipping views shows a white background

I am using the flip animation to animate between two views in my viewcontroller. The problem is that the background shows a white blank background while the animation is taking place. I would like to show a black background.
I tried setting the background color of the main view to black both in IB and code. But the background is still white.
Can someone please help me.
Thanks.
Adding the code
[self setContentView:[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]];
contentView.backgroundColor = [UIColor blackColor];
[contentView addSubview:toolbar];
[self setView:contentView];
[contentView release];
frontView = [[FrontView alloc] initWithFrame:viewFrame];
[frontView setViewController:self];
[self.view insertSubview:frontView belowSubview:toolbar];
//Initializing the back view here too
//on button click, executing normal flip code
Even after this I get a white background
I think your issue might be that the UIWindow is shown during the animation. To fix this issue, set the background color of your main window. You can do this in code or in IB.
You begin by creating a fake main view, and set its background to black:
// Create the main view
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor blackColor];
self.view = contentView;
[contentView release];
Then, you create your front and back views, and add them to your main view:
// create front and back views
UIView *frontView = ...
UIView *backView = ...
If you are using IB, skip the previous step and add directly your views
// add the views
[self.view addSubview:backView];
[self.view addSubview:frontView];
Now do the flip animation as usual.
EDIT: Probably it does not work because in your code you are adding the frontView below the toolbar. Add first the backView, then the frontView and finally the toolbar using the addSubview: method. Then, use the following code to animate the flip:
- (IBAction) flipView{
// Start Animation Block
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
// Animations
[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
// Commit Animation Block
[UIView commitAnimations];
}
Since the code performs [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; the order in which you add the subviews is relevant.