I have added a viewcontroller in the window of appdelegate class like this:
-(void)showSearchView:(BOOL)view
{
if(view)
{
searchViewController = [[SearchView alloc] initWithNibName:#"SearchView" bundle:nil];
CGRect viewFrame=searchViewController.view.frame;
viewFrame.origin.y=-1024;
viewFrame.origin.x=248;
[window addSubview:searchViewController.view];
searchViewController.view.frame = viewFrame;
[UIView beginAnimations:#"UIBase Hidden" context:nil];
[UIView setAnimationDuration:0.5];
searchViewController.view.transform = CGAffineTransformMakeTranslation(0,1024);
[UIView commitAnimations];
}
else
{
[UIView beginAnimations:#"UIBase Shown" context:nil];
[UIView setAnimationDuration:0.5];
searchViewController.view.transform = CGAffineTransformIdentity;
[UIView commitAnimations];
[self performSelector:#selector(doTHis) withObject:nil afterDelay:1];
}
}
This gets called from other classes through this command
[apd showSearchView:YES];
where apd is object of appdelegate class
Everything is working fine till here but when i try to rotate it does not rotate. I have even returnd YES in the following method and still it does not rotate:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
What should be done?
Please remember that UIWindow does not rotate. Perhaps You should add a base view controller and do your rotation.
Related
I had an application in which i am having a view controller which is an appdelegate instance.I am adding that view to the self.navigationcontrollers view in order to place it above navigation bar.lke this `
if(appDelegate.viewcontroller==nil)
{
appDelegate.viewcontroller = [[ViewController alloc] init];
[self.navigationController.view addSubview:appDelegate.viewcontroller.view];
NSLog(#"My view frame: %#", NSStringFromCGRect(appDelegate.viewcontroller.view.frame));
appDelegate.viewcontroller.view.tag=7;
appDelegate.viewcontroller.view.frame =CGRectMake(0,480,300,460);
[UIView animateWithDuration:.50
animations:^{
appDelegate.viewcontroller.view.frame =CGRectMake(0,30,300,440);
}];
[appDelegate.viewcontroller viewWillAppear:YES];
}
else
{
NSLog(#"My view frame: %#", NSStringFromCGRect(appDelegate.viewcontroller.view.frame));
appDelegate.viewcontroller.view.frame=CGRectMake(0, 30,300, 440);
[self.navigationController.view addSubview:appDelegate.viewcontroller.view];
appDelegate.viewcontroller.view.frame =CGRectMake(0,480,300,460);
[UIView animateWithDuration:.50
animations:^{
appDelegate.viewcontroller.view.frame =CGRectMake(0,30,300,440);
}];
[appDelegate.viewcontroller viewWillAppear:YES];
}
...Now i am adding another viewcontrollers view in to this view by
contactphoneForAddfriend= [[EventsViewController alloc]initWithNibName:#"EventsViewController" bundle:nil];
contactphoneForAddfriend.orgarray=self.eventsArray;
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.80];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:
UIViewAnimationTransitionFlipFromRight
forView:self.view cache:NO];
[self.view addSubview:contactphoneForAddfriend.view];
[UIView commitAnimations];
` and then from that view controller when i am going in to the background of the application ...that appdelegate viewcontroller is showing as nil.How come this happen.after all its an appdelegate variouble.when i remove he added view and then go background it is there.Can anybody point me in where i am going wrong?
Checked you code.And found viewController is not nil.Check yourself by applying some code in this method
- (void)applicationDidEnterBackground:(UIApplication *)application
{
if (self.viewController==nil) {
NSLog(#"ViewController is nil");
}else{
NSLog(#"ViewController Has value %#",NSStringFromClass([self.viewController class]));
}
}
I've set up a UIViewController that holds two other controllers:
MainVC -> SubVC1
-> SubVC2
At start, I show the SubVC1's view. The user can then switch to SubVC2's view:
- (void)showOtherSide:(id)sender
{
UIView *currentView = [self.view.subviews objectAtIndex:0];
BOOL flipToRight;
UIView *newView;
if (currentView == subVC1.view)
{
newView = subVC2.view;
flipToRight = YES;
}
else
{
newView = subVC1.view;
flipToRight = NO;
}
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
if (flipToRight)
{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:currentView cache:YES];
}
else
{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:currentView cache:YES];
}
[currentView removeFromSuperview];
[self.view addSubview:newView];
[UIView commitAnimations];
}
The problem now is that even in the simulator the first back and forth flips don't show up, instead the user sees the new view immediately. Because I set the animation caching to YES, the following flips show the animation (at least most of the time!).
I tried to put the animation code in the viewDidAppear: method too, but without any improvement.
Are there any good practices to pre-cache the animations?
I want to know how to change view on button click in iPhone without navigation controller?
If you're doing this with a UIViewController, you would probably do this like following:
- (IBAction)change {
UIViewController* viewController = [[UIViewController alloc] init];
[self.view addSubView];
// Save the UIViewController somewhere if necessary, otherwise release it
}
Not sure why you don't want to use a UINavigationController though. If it's the navigation bar at the top you don't want to see, there's a property for that so you can hide that bar. Not sure about it's name, probably navigationBarHidden or something like that. You can look that up in the API.
There are many different ways you can do that, and you should possibly provide more information about your app.
A generic way to do it is the following, with animation:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[vc1 viewWillDisappear:YES];
[vc2 viewWillAppear:YES];
vc1.view.hidden = YES;
vc2.view.hidden = NO;
[vc1 viewDidDisappear:YES];
[vc2 viewDidAppear:YES];
[UIView commitAnimations];
In this case, both views are there, you only hide/show them as you need. Alternatively, you could add/remove the view from their superview:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[vc1 viewWillDisappear:YES];
[vc2 viewWillAppear:YES];
[vc1 removeFromSuperview];
[masterController.view addSubview:vc2.view;
[vc1 viewDidDisappear:YES];
[vc2 viewDidAppear:YES];
[UIView commitAnimations];
Place this in Button IBAction method
[mCurrentView removeFromSuperview];
[self.view addSubView:mNewView];
Assume you have two view myView1 and myView2 and one button myUIButton in memory
myView1.tag = 1;
myView2.tag = 2;
myUIButton.tag = 1; //Current visible view is myView1
-(void) ButtonCLicked:(id) sender
{
UIButton* myButton = (UIButton*)sender;
if(sender.tag == 1)
{
[myView1 removeFromSuperview];
[self addSubview:myView2]
myButton.tag = myView2.tag;
}
else
{
[myView2 removeFromSuperview];
[self addSubview:myView1]
myButton.tag = myView1.tag;
}
}
You can place two UIView variables in the header file and hide/show one of them or you can make another layer over the existing view like this:
-(IBAction)changeView {
UIView *view = [[UIView alloc] initWithNibName:#"letMeSeeThis" bundle:nil];
[self.view addSubview:view];
}
I'd like a UIView to slide up from the bottom of the screen (and stay mid-screen) like a UIActionSheet. How can I accomplish this?
UPDATE:
I am using the following code:
TestView* test = [[TestView alloc] initWithNibName:#"TestView" bundle:nil];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
test.view.center = CGPointMake(160,100);
//test.view.frame = CGRectMake(0, 0, 160, 210);
[[[UIApplication sharedApplication] keyWindow] addSubview:test.view];
[UIView commitAnimations];
The view seems to be animating from the corner and appearing in the corner. How can I make it slide up from the bottom? Getting close!
Do what Matt did here, but just change the values and direction. I have code at home to do this from the bottom if you need it later (I'll update this post).
Link: http://cocoawithlove.com/2009/05/intercepting-status-bar-touches-on.html
Also, don't forget to take out the bit of code that shifts the main view downward (so instead the UIView just pops over top like an ActionSheet)
Updated with code:
This is what I use in one of my apps to show/hide a little "options" view:
- (void)toggleOptions:(BOOL)ViewHidden
{
// this method opens/closes the player options view (which sets repeat interval, repeat & delay on/off)
if (ViewHidden == NO)
{
// delay and move view out of superview
CGRect optionsFrame = optionsController.view.frame;
[UIView beginAnimations:nil context:nil];
optionsFrame.origin.y += optionsFrame.size.height;
optionsController.view.frame = optionsFrame;
[UIView commitAnimations];
[optionsController.view
performSelector:#selector(removeFromSuperview)
withObject:nil
afterDelay:0.5];
[optionsController
performSelector:#selector(release)
withObject:nil
afterDelay:0.5];
optionsController = nil;
}
else
{
optionsController = [[PlayOptionsViewController alloc] init];
//
// Position the options at bottom of screen
//
CGRect optionsFrame = optionsController.view.frame;
optionsFrame.origin.x = 0;
optionsFrame.size.width = 320;
optionsFrame.origin.y = 423;
//
// For the animation, move the view up by its own height.
//
optionsFrame.origin.y += optionsFrame.size.height;
optionsController.view.frame = optionsFrame;
[window addSubview:optionsController.view];
[UIView beginAnimations:nil context:nil];
optionsFrame.origin.y -= optionsFrame.size.height;
optionsController.view.frame = optionsFrame;
[UIView commitAnimations];
}
}
One way would be to use the present modal view controller on the view controller:
presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
For more info take a look at the UIViewController documentation.
EDIT: If you want a mid-screen view you'll need to animate it into position as #jtbandes has pointed out. I suggest also adding some candy to UIView animation block:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
myView.center = CGPointMake(x,y);
[UIView commitAnimations];
You can then move it again if you need to go full screen or dismiss it.
You'll have to move the view yourself, by setting its center or frame. I'll let you figure out what to set those to. But for the animation:
// set the view to its initial position here...
[UIView beginAnimations:nil context:NULL];
// move the view into place here...
[UIView commitAnimations];
Check out this post: http://blog.yetanotherjosh.com/post/33685102199/3-ways-to-do-a-vertical-transition-with
I'm going with the modal window approach.
Try this solution.... it works
#pragma mark - Date Selector View PresentModelView with Transparent ViewController
- (void) showModal:(UIView*) modalView {
CGRect rect=modalView.frame;
rect.origin=CGPointMake(0, 0);
self.tutorialView.frame=rect;
UIWindow *mainWindow = [(AppDelegate *)[UIApplication sharedApplication].delegate window];
CGPoint middleCenter;
middleCenter = CGPointMake(modalView.center.x, modalView.center.y);
CGSize offSize = [UIScreen mainScreen].bounds.size;
CGPoint offScreenCenter = CGPointMake(offSize.width / 2.0, offSize.height * 1.5);
modalView.center = offScreenCenter;
if ([[mainWindow subviews] containsObject:modalView]) {
[modalView removeFromSuperview];
}
[mainWindow addSubview:modalView];
[mainWindow bringSubviewToFront:modalView];
// Show it with a transition effect
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
// animation duration in seconds
modalView.center = middleCenter;
[UIView commitAnimations];
}
// Use this to slide the semi-modal view back down.
- (void) hideModal:(UIView*) modalView {
CGSize offSize = [UIScreen mainScreen].bounds.size;
CGPoint offScreenCenter = CGPointMake(offSize.width / 2.0, offSize.height * 1.5);
[UIView beginAnimations:nil context:(__bridge void *)(modalView)];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(hideModalEnded:finished:context:)];
modalView.center = offScreenCenter;
[UIView commitAnimations];
}
- (void) hideModalEnded:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
UIView *modalView = (__bridge UIView *)context;
[modalView removeFromSuperview];
}
I'm having some trouble getting a view to flip. I have the following code in my View Controller:
- (void)loadFlipsideViewController {
ProblemViewFlipController *viewController = [[ProblemViewFlipController alloc] initWithNibName:#"ProblemViewFlip" bundle:nil];
self.problemViewFlipController = viewController;
[viewController release];
}
- (void) flipView {
if (problemViewFlipController == nil) {
[self loadFlipsideViewController];
}
UIView *mainView = self.view;
UIView *flipView = problemViewFlipController.view;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:([mainView superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight) forView:self.view cache:YES];
if ([flipView superview])
{
[flipView removeFromSuperview];
[self.view addSubview:mainView];
}
else
{
[mainView removeFromSuperview];
[self.view addSubview:flipView];
}
[UIView commitAnimations];
}
The problem is, is that when I call flipView, the view is replaced with a blank view (i.e. nothing in the view I'm flipping to is displayed).
Is there something obvious I'm missing here? (I suspect there is!)
Not positive, but I think you need to use a 'controller' to flip the views. Looks like you're using one of the flipped views as the controller. Just add a root controller to flip your views.
Code like this should work from the root controller:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES]; // self.view is the root controller's view
[mainViewController viewWillAppear:YES];
[flipViewController viewWillDisappear:YES];
[flipViewController.view removeFromSuperview];
[self.view addSubview:mainViewController.view];
[flipViewController viewDidDisappear:YES];
[mainViewController viewDidAppear:YES];
[UIView commitAnimations];
Based on the variable names, it looks like this is adapted from the default "Utility" application template you get from XCode. If the template project works, and yours doesn't, then you've obviously changed something you shouldn't have :-)
Chances are, one of the outlets in your controller that should be pointing at a view, isn't. Double-check your Nibs, and check the values of the outlets in the debugger. If all else fails, start over again from the template, and see at what point it stops working.