I have a Box2D world which works great. I'm using it in a simple iOS game where the user tilts the device to push bodies around the screen racking up points when a certain body collides with another.
It was working fine when it was buried a couple layers deep in my app in a test controller. I invoked it from a button on my menu screen and a button on the game screen would return to the menu just fine via popToViewController. But once I saw how great it worked I realized that I wanted the game to be the first screen a user sees (after the default loading image). So now the app loads the world and the game is on right off the bat without any problems.
Until the user taps the menu button to get to the menu screen - another view controller. The menu controller loads fine and everything works there as expected. BUT when one taps the back button to return to the game/world the images/bodies are distorted. The distortion varies depending on how they happened to be rotated when the menu controller got pushed onto the navigation stack. Sometimes they are enlarged and sometimes smooshed.
I did try pausing the world (by not calling Step) when loading the menu controller, but that did not help with the image distortion problem.
Here is the code where the menu controller gets loaded:
//unhide the navbar for the next screen
[self.navigationController setNavigationBarHidden:NO];
MenuViewController *mvc = [[MenuViewController alloc]init];
[self.navigationController pushViewController:mvc animated:YES];
[mvc release];
And here is where the game's view controller gets loaded by the app delegate in application didFinishLaunchingWithOptions:
B2DViewController *b2dvc = [[B2DViewController alloc]init];
UINavigationController *navcon = [[UINavigationController alloc] init];
[navcon setNavigationBarHidden:YES];
[navcon pushViewController:b2dvc animated:NO];
[window addSubview:navcon.view];
[b2dvc release];
[window makeKeyAndVisible];
The images come in via a xib. One is button and one is an imageView. Both are added to dynamic bodies which are configured thusly:
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(boxDimensions.x, boxDimensions.y);
...
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 3.0f;
fixtureDef.friction = 0.3f;
fixtureDef.restitution = 0.5f;
...
I tried hiding all the subviews but, as you might suspect, that only hid them from view, not from the forces of distortion. I also turned off all the stretching and resizing stuff in IB, to no avail (I was just guessing).
I'd be grateful for any assistance or ideas that anyone might have.
Instead of pushing the menu controller onto the navigation controller and then adding the navigation controller to the view I instead used presentModalViewController: animated. This didn't fix the problem, but once I commented out [self.navigationController setNavigationBarHidden:NO]; the problem was resolved.
//unhide the navbar for the next screen
//[self.navigationController setNavigationBarHidden:NO];
MenuViewController *mvc = [[MenuViewController alloc]init];
[self presentModalViewController:(UIViewController *)mvc animated:YES];
[mvc release];
It seems that the NavigationBar was smashing the images? I'd like to look into this further as the navigation bar can be a handy thing, but I don't have time now, which probably means I'll never get around to it.
Related
I am new bee in iPhone and just started development in it.
Learning a lot because of friends like you!
I just learnt how to go to another screen from current screen and i Did well due to tutorials from Internet.
But now the problem is when new screen comes up it animates from Bottom to Up and when we click DONE button to close the screen it goes from Up to Down. I have seen many applications in iPhone that animate the new screen from Right to Left and again from Left to Right.
What Piece of code do i need to add into the following to animate it toward left.
Please guide me Friends
MainScreen *screen = [[MainScreen alloc] initWithNibName:#"MainScreen" bundle:[NSBundle mainBundle]];
self.mainScreen = screen;
[self presentModalViewController:mainScreen animated:YES];
There are four different ModelTransitionsFor View Controllers.
You can set those for
screen.modalTransitionStyle = UIModalTransitionStylePartialCurl;
There are 3 other Styles you can check on Apple Site Link
If you need to do something like Navigation Style. you need to push your view controller to navigation stack.
[self.navigationController pushViewController:screen animated:YES];
Instead of this
[self.navigationController presentModalViewController:yourView animated:YES];
use this
[self.navigationController pushViewController:yourView animated:YES];
If you have Navigation based app then replace code with below.
MainScreen *screen = [[MainScreen alloc] initWithNibName:#"MainScreen" bundle:[NSBundle mainBundle]];
self.mainScreen = screen;
[self.navigationController pushViewController:screen animated:YES];
There are few modal view transitional styles available. Check apples documentation on this.
Also there are few uiviewtransitionanimation styles also described neatly in apple's guide.
The context:
I am working on an app that maintains a list of contacts along with their record IDs for it's own reference.
When the user needs to change the number associated with a specific contact within the app, I am trying to display the ABPersonViewController so the user can choose the new number from the contact in AB.
The problem:
The problem is that the ABPersonViewController that is opened is starting all the way from the top of the screen as if it does not know that there is a navigation bar on the top.
As a result some of the top part of the ABPersonViewController screen (the top part of the person image and the top part of the name) is underneath the navigation bar.
Ideally i want it to look like this, but not in edit mode: http://developer.apple.com/library/ios/documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Art/person_view.jpg
Also I wanted to add a "cancel" button to the top right part of the nav bar. Trying to add that as a bar button is not working either.
The code:
this is how I am adding the ABPersonViewController to the navigationController:
ABPersonViewController *personViewController = [[ABPersonViewController alloc] init];
personViewController.personViewDelegate = self;
personViewController.displayedPerson = person;
[self.m_circleNavController pushViewController:personViewController animated:YES];
[personViewController release];
The self here is a UIVIewController.
The m_circleNavController is the UINavigationController to which the UIVIewController belongs.
I tried these 2 ways of showing the person view, but both behave the same way.
[self.m_circleNavController pushViewController:personViewController animated:YES];
[self.navigationController pushViewController:personViewController animated:YES];
I'm not too sure what I am doing wrong, or what is the best way to do it.
I tried a lot of different ways to display it in vain.
The viewcontroller was behaving as though it was starting about 40 pixels above the top edge of the screen.
I was able to fix it in a very weird way finally. In the init function of the viewcontroller I added the following line:
self.view.bounds = CGRectMake(0, -43, 320, 440);
But still no clue as to why it happens this way. I was to close to the deadline to look for a decent solution.
Hello I've been having the same problem as of the new iOS. When this happens on my custom view controllers I have been able to correct it with:
if (self.interfaceOrientation != UIInterfaceOrientationPortrait) { // UI is in landscape position
[self.tableView setContentInset:UIEdgeInsetsMake(32,0,0,0)];
} else { // UI is in portrait position
[self.tableView setContentInset:UIEdgeInsetsMake(44,0,0,0)];
}
But when using the ABPersonViewController I don't quite know how to handle this problem.
Hope someone has an idea...
I have a tab bar application and I want to display those views that most part of apps have, with the name of the company or the name of the app.
I've created the follow viewController
Introduction *introducao = [[Introduction alloc] initWithNibName:#"Introduction" bundle:nil];
I don't know where exactly should I insert the code to show the modal because I have a tab bar application:
[self.navigationController presentModalViewController:galeria animated:YES];
I've tried to insert these lines on appDelegate.. but didn't work.. somebody have an idea?
if you are trying to show a splash screen right when the application opens, you should use a Default.png image instead of a view controller showing an image. Check out the Apple Documentation on Human Interface Guidelines and Beginning iPhone Development.
First of all, you'll need to ensure that you have a navigation controller present to present the model view from. Otherwise in the above code you'll be messaging nil and nothing will happen. Then you'll want to put the presentModalViewController:animated: call in your app delegate's applicationDidFinishLaunching: implementation.
Thanks for all answers.. they were very useful to understand better the process..
I have found a solution that does exactly what I need! So if someone need to create those splash screens with a sequence of images it is very useful:
Just create a ImageView on the Delegates Header and do the following:
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashView.image = [UIImage imageNamed:#"Default.png"];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
to control the duration of the splash screen:
[self performSelector:#selector(removeSplash) withObject:nil afterDelay:1.5];
To remove the splash:
-(void)removeSplash;
{
[splashView removeFromSuperview];
[splashView release];
}
so If you want to create a sequence of image just create a method to change the splashView.image.. and create a NSTIMER to call it..
I have an iPhone application that I am currently converting to a universal binary to work with the iPad. I have successfully implemented everything I need in terms of layout so that full landscape functionality is now supported in my app (previously I primarily used portrait mode to display content).
But, I have one strange problem, and it ONLY occurs in landscape mode: when I push a view controller onto the stack, it takes two taps on the back button to return to the previous view controller! The first tap shows a blank view, but with the same name on the left-side back navigation button, the second tap takes the controller back to previous view like it should.
I don't have an iPad to test, so I am relying on the simulator. The problem does not show up on the iPhone and doesn't show up if you rotate back to portrait mode.
My app consists of a tabbarcontroller with navigation controllers loaded for its vc's:
//application delegate
- (void)applicationDidFinishLaunching:(UIApplication *)application
//....
WebHelpViewController *vc8 = [[WebHelpViewController alloc] init];
UINavigationController *nv8 = [[UINavigationController alloc] initWithRootViewController:vc8];
[self.tabBarController setViewControllers:[NSArray arrayWithObjects:nv1,nv2,nv3,nv4,nv5,nv6,nv7,nv8,nil]];
To implement landscape capability, the UITabBarController is overridden to autorotate when required:
//CustomTabBarController.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return [[(UINavigationController *)self.selectedViewController topViewController] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
... works fine. I navigate into new views using this method
SomeViewController *vc = [[SomeViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
[vc release];
Is this only a simulation error? How do I fix this problem?
It sounds like another ViewController is responding to:
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
Check this first.
I am developing a Window Based app for iPhone. I use Interface Builder to build Interface. I want to call a new screen with a Button Action. How can I call the screen with Button action ?
By pushing the new controller onto the top of the stack of windows. For example:
EnterNameController *newEnterNameController = [[EnterNameController alloc] initWithNibName:#"EnterName" bundle:[NSBundle mainBundle]];
[[self navigationController] pushViewController:newEnterNameController animated:YES];
Apple has an extraordinary amount of sample code, and this question (as well as many others) could easily be solved by simply visiting Apple's iPhone dev site.
iPhone Dev Site
If you are using a navigation controller, push it onto the navigation controller's stack, as alamodey suggested.
If you want it to be a modal controller (that is, slide up from the bottom and cover the previous controller's view, like the Bookmarks screen in Safari), present it as a modal view controller:
[self presentModalViewController:myNewController animated:YES];
When you want to bring the old controller back, dismiss the modal view controller. From inside the modal view controller:
[self.parentViewController dismissModalViewControllerAnimated:YES];
If you don't want to do either, just remove the current controller's view from the window and add the new controller's:
UIView * containingView = self.view.superview;
[self.view removeFromSuperview];
[containingView addSubview:myNewController.view];
If you go this route, you may want to look into +[UIView beginAnimations:context:], +[UIView setAnimationTransition:onView:], and +[UIView commitAnimations] (if I recall the method names correctly--check the documentation) to animate the transition. You should almost always animate any switch between screens in iPhone OS.
(work in .m class)
#import "classtocall.h"
- (IBAction)ButtonPressed:(id)sender
{
classtocall *mvc = [[classtocall alloc]initWithNibName:#"classtocall" bundle:nil];
[self presentModalViewController:mvc animated:NO];
}
(for window based application)
define in .h class
- (IBAction)ButtonPressed:(id)sender;
where "classtocall" is the class you want to call.
you just need to download sample applications from XCode help. Try Elements and UIcatalog. There are also other - type 'pushViewController' or 'addSubview' adn 'makeKeyAndVisible' in help and download samples
nextscreenViewController *login = [[self storyboard] instantiateViewControllerWithIdentifier:#"nextscreenidentifier"];
nextscreenidentifier.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController: nextscreenidentifier animated: YES];