In my application I don't use the upper bar that displays Wi-Fi/Date/Time because it's a game. However I need to be able to let my user to pick his music, so I'm using a MPMediaPickerController. The problem is, that when I present my controller, the controller ends up leaving a 10 pixels ( aprox ) bar at the top of the screen, just in the place the Wi-Fi/Date/Time bar, should be present.
Is there a way I could make my MPMediaPickerController bigger ? or to be presented upper in the screen ?
// Configures and displays the media item picker.
- (void) showMediaPicker: (id) sender
{
MPMediaPickerController *picker =
[[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
[[picker view] setFrame:CGRectMake(0, 0, 320, 480)];
picker.delegate = self;
picker.allowsPickingMultipleItems = YES;
picker.prompt = NSLocalizedString (#"AddSongsPrompt", #"Prompt to user to choose some songs to play");
[self presentModalViewController:picker animated: YES];
[picker release];
}
There I tried to set the size to 320x480 but no luck, the picker is still presented and leaves a space in the upper part of the screen, could anyone help me ?
Btw, here's how it looks:
alt text http://img195.imageshack.us/img195/1986/img0001yb.png
I have asked a bit, and people told me this could indeed be a bug, what do you guys think ?
This could go two ways. Yes I'd say it's a bit of a bug that the picker doesn't resize accordingly, but it could also be argued that Apple expects the picker to operate in a non-full screen environment.
Rather than try to force it to work as you'd like, I'd instead recommend turning the status bar back on while the picker is visible:
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
(To confirm, you are turing the status bar off in a similar fashion with your app, not just somehow painting over it?)
[[picker view] setBounds:CGRectMake(0, 0, 320, 480)];
Perhaps?
picker.wantsFullScreenLayout = YES;
picker.view.clipsToBounds = NO;
Related
I got a lot of problems implementing Game Center.
My game its based on Cocos2d But my Menu I do it with XIB. So the main window i make it like this:
UIWindow
UINavigationController
Navigation Bar
UIViewController [Menu]
UINavigationItem
When i click on Play I create a new View Controller called Menu2Game.h.m.xib And i add the OpenGL to this view, and then Menu2Game add it to my menu View
menu2Game = [[Menu2Game alloc] initWithNibName:#"Menu2Game" bundle:nil];
[menu2Game setView:glView];
[self.view addSubview: menu2Game.view];
I don't know why I can't add it directly... But when I click on leaderboards I do the same thing. Presenting the view directly on Menu doesn't work.
UIViewController *tempView = [[UIViewController alloc] init];
[self.view addSubview:tempView.view];
[[GameCenter sharedGameCenter] showLeaderboard:tempView];
And when I call my leaderbords its this code.
if ([self isGameCenterAvailable]) {
GKLeaderboardViewController *leaderboardController = [[[GKLeaderboardViewController alloc] init] autorelease];
if (leaderboardController != nil) {
screen = screen2;
leaderboardController.leaderboardDelegate = self;
[screen presentModalViewController: leaderboardController animated: YES];
[leaderboardController setCategory:#"015.1"];leaderboardController.view.frame.origin.y);
leaderboardController.view.bounds = CGRectMake(0, 0, 480, 320);
leaderboardController.view.center = CGPointMake(240, 160);
}
}
The problem here its that doesn't respects the application Orientation
If its in Landscape. It start in 80, 320, And finish in 480, 320
It appears and you can use it but appears not in ----> this direction it moves like with 45 degrees
And if you hold the phone in Portrait [Any]. It appears only a small fragment of the leader boards, Facing the real orientation, but the coordinated are different it takes the ones you are holding. And in my plist its not permuted portrait.
How could i fix this? I got 1 week to finish this game and this is the only thing I miss.
Thanks to everybody
I don't know why but just create should rotate and return true.., and eliminate all the code that modify the game center
this one:
[leaderboardController setCategory:#"015.1"];leaderboardController.view.frame.origin.y);
leaderboardController.view.bounds = CGRectMake(0, 0, 480, 320);
leaderboardController.view.center = CGPointMake(240, 160);
}
I am having a great deal of trouble displaying at small, live camera image in a viewController.
I would have expected the following code to show camera display to appear in a 100x 100 window, but it keeps appearing full screen!
Help appreciated.
camera = [[UIImagePickerController alloc] init];
UIView *cameraHUD = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
cameraHUD.userInteractionEnabled = YES;
[camera setSourceType:UIImagePickerControllerSourceTypeCamera];
camera.showsCameraControls = NO;
camera.navigationBarHidden = YES;
camera.toolbarHidden = YES;
camera.cameraOverlayView = cameraHUD;
[self presentModalViewController:camera animated:YES];
[self.view bringSubviewToFront:cameraHUD];
You are present a new view instead of your actual view, so by default a new UIView has contentmode= scale to fill.
You have to add for example something like:
[camera setContentMode:UIViewContentModeTopLeft];
But if you want do something cool you have to add your Camera View as subview.
I hope it can help you
bye ;)
I am adding a view that fades in that gives my user alerts like successful login etc. Unfortunately the view does not appear above the keyboard so half of it gets hidden because I am displaying it in the center.
case 401:
alertBezel = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:alertBezel];
// Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators)
alertBezel.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"37x-Checkmark.png"]] autorelease];
alertBezel.mode = MBProgressHUDModeCustomView;
alertBezel.labelText = #"Unauthorized User!";
[alertBezel show:YES];
[alertBezel hide:YES afterDelay:1];
break;
I also tried getting the key window:
[[UIApplication sharedApplication] keyWindow]
No luck.
It sounds like you should really be using a UIAlertView. That will show up over the keyboard.
Below are some resources on customizing alert views:
how i can implement a custom UIAlertview with a progress bar and a cancel button?
http://www.skylarcantu.com/blog/2009/08/14/custom-uialertview-color-chooser/
You could animate it up, by modifying its property when the keyboard shows up, or when your user go to the next field.
I have a very simply UIViewController, and I'm trying to figure out how to use willRotateToInterfaceOrientation. my UIViewController has a very simple viewDidLoad method:
-(void)viewDidLoad {
[super viewDidLoad];
theBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];
theBar.tintColor = [UIColor orangeColor];
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:#"The Title"];
item.hidesBackButton = YES;
[theBar pushNavigationItem:item animated:YES];
[item release];
[self.view addSubview:theBar];
}
So basically, I just have a UINavigationBar at the top of my controller. That's it. I implemented some methods for rotation, based on what I found online:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
-(void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {
if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)) {
theBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 640, 48)];
}
}
So, I launch the app in portrait mode, and then I twist in in landscape mode. And basically, theBar still stays it's normal size, and doesn't get resized. I'm sure this is a silly question, but what is the proper way to use the rotation capability? I want to make it so that it also works if the app is launched in landscape mode. What is the best way to initialize my components when the UIViewController first launches, keeping in mind that I want support for both orientations, and also keeping in mind that I want to be able to change the size of everything based on orientation changes throughout the duration of the life of the UIViewController? Thanks!
What you want to do is change the frame of your existing theBar object, and not instantiate a new one. You can do that with something like this:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation
duration:(NSTimeInterval)duration {
CGRect f = CGRectMake(0,
0,
CGRectGetWidth(self.view.frame),
CGRectGetHeight(theBar.frame);
theBar.frame = f;
}
Note that the value of self.view.frame is used, which contains values post rotation. Also note that the function I'm using here is different than yours. I haven't tested it with the function you're using, so I can't say if that'll work or not. Finally, you can avoid this altogether by just setting the autoresizingmask on theBar in viewDidLoad instead:
[theBar setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];
How can I set correct orientation of MPMediaPickerController ?
I've return YES in shouldAutorotateToInterfaceOrientation, but i have bad frame for Landscape (if show MPMediaPickerController in Portrait first, and conversely).
I've rotating my device chaotically and sometime frame set to correct himself!
I've find the method to set frame by rotating - need rotate to 180 degreess.
For example, if you have good frame in Portrait, when you rotate to Landscape - you have bad frame (from Portatait), but if you rotate to other landscape (to 180 degreess), then frame set to Landscape...
Why ?
How can i set the frame after rotation correct always ?
regards,
Not sure whether you are interested in the solution or not, since you asked this in 2010.
Anyway, after a few searches here is what I found:
MPMediaPickerController DOES NOT SUPPORT LANDSCAPE ORIENTATION.
In order to make the MPMediaPicker appear nicely in landscape orientation, we can make use of PopOverController. Basically, we create a pop over, and insert the picker into it. PopOverController, when displayed properly from the rootViewController, will indeed follow the orientation of the device.
Here is the rough code. It works, but needs some cleaning up. Probably best you check whether
the popover is nil or not, otherwise it will just stack up on itself each time the user tap on the button.
- (IBAction)showMediaPicker:(id)sender
{
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAny];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = YES;
mediaPicker.prompt = #"Select musics...";
UIPopoverController *colorPickerPopover = [[[UIPopoverController alloc]
initWithContentViewController:mediaPicker] retain];
[colorPickerPopover presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
A little more note: this IBAction is tied to a Toolbar Bar button.
I'm simply pushing it onto my navigation controller:
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAny];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = NO;
mediaPicker.prompt = #"Select songs...";
[[self navigationController] pushViewController:mediaPicker animated:YES];
Granted this only works in the context of a navigation controller, but it works and is simple!
here is some sample code you can try it one , after rotation you have to set media palyer view in center of self.view, here some sample code... you have to add MediaPlayer Framework at first....
NSString* moviePath = [[NSBundle mainBundle] pathForResource:#"PATRON_LOGO_3" ofType:#"mp4"];
NSURL* movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *playerCtrl = [[MPMoviePlayerController alloc]initWithContentURL:movieURL];
playerCtrl.scalingMode = MPMovieScalingModeFill;
playerCtrl.controlStyle = MPMovieControlStyleNone;
[playerCtrl.view setCenter:CGPointMake(240, 160)];
[playerCtrl.view setTransform:CGAffineTransformMakeRotation(M_PI/2)];
playerCtrl.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:playerCtrl.view];
[playerCtrl play];
i think it works fine , this is for landscape mode for portrait we have to set frame according to portrait frame like..
playerCtrl.view.frame = CGRectMake(0, 0, 480, 320);
after that we have to set to center of view.