When we creating application with MPMoviePlayer (within custom UIViewController) and with overlay UIViewController on top of movie player what is better:
- Load movie in player with self.view.presentModalView... or self.view.addSubView...
Or is there any other better way. I now work with modal views and everything works except I have to implement some custom rotations. I am looking for more clear way to make this.
Ok maybe some more details. In iPhone app I add player like modal view and add overlay view to it and that works. But this is universal app and it doesn't work on iPad the same way it works on iPhone. In ipad splitView my player is on details side (nonfullscreen), when I double tap player it goes fullscreen. And now player is key window. Here is the biggest issue. I tried to add overlay view as subviw and modal view and I made it but that overlay is not aware of device orientation, and I have to transform overlay elements and this is what I am trying to avoid. Is there any way to detect rotation on that view?
Simple and most elegant solution:
Do not use the "real" fullscreen mode but scale the MPMoviePlayerController's view towards a screen-filling size - MPMoviePlayerController.view.frame = CGRectMake(0.0f, 0.0f, 768.0f, 1024.0f);. Keep the MPMoviePlayerController's view on top of a regular UIViewController's view that allows rotations (addSubview). Keep your custom interface view on top of the MPMoviePlayerController's view (addSubview) and presto, you will get a properly rotating video player no matter if you run it in "fullscreen" or not.
I found one solution but I am not very proud because I this that there is some better way, but this workaround works:
- In project I have on singleton class that contains some global data for me.
- When application start in detail view (UISplitView) willAnimateRotationToInterfaceOrientation method is called first. Here I get current orientation and store it in singleton class.
- Later when I add overlay on top of player I read data from singleton and transform overlay elements.
According to above I did something like this:
mp = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]];
mp.movieSourceType = MPMovieSourceTypeStreaming;
mp.view.frame = CGRectMake(0.0f, 0.0f, 1024.0f, 768.0f);
[self.view addSubview:mp.view];
mp.controlStyle = MPMovieControlStyleNone;
[self.view addSubview:self.myOverlay];
[mp play];
Actually it was so easy! Just choose control style to None and add your low opacity view on the player view.
Related
I have a UIView that represents a game screen. I have a reset button allowing users to replay that level. For the reset though I want to reset ALL UI controls to their default state as upon completion various animations take place that fade in/out text and move around images etc.
What I would like to do is replace the existing UIView with another copy of itself (with animation). How can I do this whilst not breaking the UINavigation stack? When a user presses back on the new screen I want them to goto the original parent UIView and not the game screen that was replaced.
I do something similar using a mask view.
Create a mask view, a UIView set as your starting view (or just an image).
Animate a transition from your game view to your mask view.
Reset your game view.
Remove your mask view, showing your game view.
Doing so your UINavigation stack won't be broken, because you actually use just one active view (game view) and a static mask to cover your view for transition.
On the top of your controller stack you presumably have controller that "owns the game view"?
I also assume that you are using a custom view within your controller to do most of the view stuff.
If this is the case, then you should be able to alloc, init another instance of your game view which will be in default state. Set it's alpha to 0.0f and add it to the view hierarchy, then animate its alpha to 1.0f and in the animation completion block remove and release th sold view that you no longer need.
Alternatively you could define the start condition, positions, values etc. and then just animate back to them when the button is pressed.
Hope this helps :)
I assume you have code to initialize all of you subviews and game-related data members right?
move that code to a separate method and have the reset button call the method.
I usually have a -setupSubviews method on each custom view i create and i call it each time i need to reset my view to its original state, for example:
- (void)setupSubviews
{
_titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
[self addSubview:_titleLabel];
_activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectZero];
_activityIndicator.hidesWhenStopped = YES;
[self addSubview:_activityIndicator];
_loading = NO;
}
I'am doing a game, when the player lose, and screen of Game Over appears. But my Game Over screen its in a UIViewController. I call it in my Director, and alls right.
The Game over screen appears like overlay in the game
But i am using Custom Fonts, and in my Game Over screen I want to use it. But how could I use only "CCLabelBMFont" in the Game Over.
I think a way (no the better one). Its that you print in a bigger z-index than the Game Over the text I want it with "CCLabelBMFont". But I want to have all the stuff of Game Over in the GameOver.m
What could I do? Thanks to everybody.
To present anything from Cocos2D on top of a UIKit view, you'll have to make the Cocos2D view transparent and introduce a dummy view. You can't achieve this effect with the z order because that affects only the nodes in Cocos2D's OpenGL view.
To make the Cocos2D view transparent you need to change the color depth to 32 bit (RGBA8888) from the default 16-Bit mode in the EAGLView initialization (app delegate). Then setup the view hierarchy with a dummy view, so that you can actually add UIKit views in the background and the Cocos2D view as the foremost view.
The basic approach is to do this in your app delegate didFinishLaunching method:
UIView* dummyView = [[UIView alloc] initWithFrame:[window bounds]];
[dummyView autorelease];
[dummyView addSubview:[CCDirector sharedDirector].openGLView];
rootViewController.view = dummyView;
[window addSubview:rootViewController.view];
// make the cocos2d view transparent:
glClearColor(0.0, 0.0, 0.0, 0.0);
[[CCDirector sharedDirector] openGLView].opaque = NO;
From then on you can use the dummyView to manage the view hierarchy. For example, when you add your game over view to the dummyView, you want to call sendToBack on it so that it is drawn behind the cocos2d view.
The entire process with all things to consider is described in detail in my Learn Cocos2D Game Development book (2nd Edition).
I want to customize new camera overlay view, so need figure out one way to put new view above self.imagePickerController.cameraOverlayView.
I have tried those ways
[self.view bringSubviewToFront:self.imagePickerController.cameraOverlayView];
[self.imagePickerController.cameraOverlayView bringSubviewToFront:self.view];
[self.view insertSubview:self.view aboveSubview:self.imagePickerController.cameraOverlayView];
But none can work.
Seem that the only way is
self.imagePickerController.showsCameraControls = NO;
Therefore build my own components like iPhone.Camera
I think the idea with the cameraOverlayView is that you use this as a base UIView for anything you'd like to overlay on the camera view. This main overlay view can be transparent, and you just need to place whatever views you want to overlay on the camera as subviews of it.
You can order these subviews however you want within the overlay to achieve the desired visual effects.
Additionally, I recommend watching the WWDC 2010 video session 421 - "Incorporating the Camera and Photo Library in your App", where they go into detail on how to manage camera overlay views. I believe that Apple's PhotoPicker sample application also shows this off.
I have main menu in my app supporting only landscape mode.
I implement landscape restriction by setting up UIRootViewController::shouldAutorotateToInterfaceOrientation:...
And I have another scene with portrait mode support.
So the problem appears when I pass from another scene to main menu in portrait mode: the app doesn't rotate to landscape automatically, and I can't find a code method to manually rotate it.
Is there a solution? Would be thankful.
Edit: Excuse me, I forgot to add details. RootViewController is common for menu and another scene. And what is more - these scenes are in one common view (my app uses OpenGL)
So before I enter menu from portrait scene I set UIRootViewController::shouldAutorotateToInterfaceOrientation: to return YES for landscape only.
If your other scene with portrait support is controlled by another UIViewController, then you can use that view controller's -shouldAutorotateToInterfaceOrientation: to define its behavior. In many cases, this alone should be enough. Of course, if you need to do some fancy rotations for some view controller but not for others, then things get a bit trickier.
There is no easy way to do this, except [UIDevice setOrientation:], which is not open to developers, and leads to application rejection by Apple.
You can apply a rotation to your layer which will create the exact same effect.
myview.layer.transform = CATransform3DMakeRotation(M_PI/2, 0.0f, 0.0f, 1.0f);
in some iPhone/iPad Apps you can see screens sliding in and out.
How does the straight slide in/out work?
I could only find Curl and Flip for animation:
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
UIViewAnimationTransitionCurlUp,
UIViewAnimationTransitionCurlDown,
not sure what you mean by sliding in and out, perhaps provide an example app with it
I think you mean pushing a view to the left to reveal the next view under it or something similar
-(void) slideView:(UIView *)uiv_slide toReveal:(UIView *)uiv_reveal withDuration:(double)d_duration {
//Add the subview to the ViewController's view
[self.view addSubview:uiv_reveal];
//Bring the view to slide to the front
[self.view bringSubviewToFront:uiv_slide];
//Make an animation to slide the view off the screen
[UIView animateWithDuration:d_duration
animations:^ {
uiv_slide.center = CGPointMake(-1*(uiv_slide.frame.size.width/2), uiv_slide.frame.size.height/2);
}
];
}
hopefully the code helps
If you make your app based on the navigation app template, the transitions for going from view to view will have that slide in/out animation.
Take a look at some custom animations here. This will allow you to animate your views however you want. You can also use the apple navigation controller to build a drill down structure to your apps. Those view will automatically slide transition.