TapJoy rotates all my UIViewContollers used inside the game - iphone

I use TapJoy SDK in my an OpenGL based game (based on Maze+ code)
when i use the following code in the App Delegate to show full screen ads
[TapjoyConnect showFeaturedAppFullScreenAd];
or even use the following code in the more games view to show more games
[TapjoyConnect showOffersWithViewController:self withInternalNavBar:NO];
i got all my View controllers (like more games view and news view) rotated see the screen shot
do you have any idea how to fix this problem?

Adding this line should fix the problem.
[vc.view setTransform: CGAffineTransformMakeRotation(M_PI / 2)];
It should come before this:
vc.view.frame = view.frame;
[view addSubview:vc.view];

Related

iOS: is it possible to attechment of MFMailComposeViewController with Animation?

I am working on attach images into MFMailComposeViewController everything is fine working but i want to know that is it Possible to give animation of Attachment?
For Ex:- When we attach images from Photo Gallery in iPhone Device. and while select mail Button that all selected Images Move's in MailComposeViewcontroller with Nice ANIMATION.
So please can any-buddy guide me this stuff is possible or not.? and if YES then how can i set Animation of Attachment.
There exists some semi-solution. You can in fact add any UIView as subview of you main app's window. It will than sit on top of all apps content. Using this you can simulate animation of attaching image to MailComposeViewcontroller
See my example code. This code slides image view from top of the screen to mail composer so it imitates adding of image as attachment. Everything is commented.
// Get apps main window
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
// Setup frames of animated image view in apps window - adjust to your needs
CGRect finalImageFrame = CGRectMake(30, 220, window.frame.size.width-60, 100);
CGRect initialImageFrame = finalImageFrame;
initialImageFrame.origin.y = -initialImageFrame.size.height;
// Create image view to be animated as attachment
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"myImage"]];
imageView.frame = initialImageFrame;
imageView.backgroundColor = [UIColor redColor];
// Add animated image view to window
[window addSubview:imageView];
// Animate image view with slide in from top
[UIView animateWithDuration:0.4
animations:^{
imageView.frame = finalImageFrame;
}];
// Present mail composer
[self presentViewController:mailComposer animated:YES completion:^{
// Once the controller appears, hide the image view - adjust this animation according to you needs
[UIView animateWithDuration:0.4
animations:^{
imageView.alpha = 0;
} completion:^(BOOL finished) {
[imageView removeFromSuperview];
}];
}];
Of course the code may need some adjustments and polishing, but it shows the concept. You can play with animations to make some better effect. There is a lot of animation tweaks I would add, but I wanted to keep the example code as short at it can be ;-)
That is iOS custom animation effects and is not exposed as iOS API's so no you cannot get this effect out of box. The reason I know that this effect is not exposed to developers is from Apple iOS 6 Docs. There is only one method which deals with animate and its the standard one.
What you can try is this. After the user has selected image(s) from his photo gallery (i.e. from ALAssetsLibrary) you can animate a "image" that looks like a MFMailComposeViewController. The animation would similar to what iOS provides i.e. background fading, MFMailComposeViewController appearing and the images sitting in the "body" section of the mail. Once the animation finishes, remove the "image" of MFMailComposeViewController and show the actual call MFMailComposeViewController invoked with animaiton:FALSE option. Hope I was clear. Essentially what you are providing is an illusion of MFMailComposeViewController and once animation is done, taking away the illusion and showing the reality.
Theoretically this could work but exact animation timing and user perceived feel has to be tested out.

Application Screen distorted after iOS upgrade

The application which runs smoothly on 4.0.1 when was tried on run on 4.2.1 produced distorted screen i.e., screen somewhat moved to left by 20%. Phones on which iOS 4.0.1 and 4.2.1 are installed are 2 different phones. What could be the problem?
We observed that wherever we have added as subview this problem is occurring.
Thanks,
Satish
From your description, I think it is either that you are not setting the correct view.autoresizingMask properly or there is a subtle change in how views are being laid out.
Try setting the frame of the view that moved explicitly and see what happens.
[view setFrame:CGRectMake(0, 0, 320, 460)]
Some related piece of code and/or screenshots would definitely help. Also, is it a UIKit application or a Cocos2D game?
EDIT: Since you can't provide code (or a stripped-down example version) I'll just post some code that I've been using.
Usually when I add subviews to "fill" a parent view, I had do the following:
UIView *parent = nil; // find parent view
UIView *child = nil; // child view to add to parent
[parent addSubview:child];
CGRect frame = [parent frame];
frame.origin.x = 0;
frame.origin.y = 0;
[child setFrame:frame];
If you have done that and it still does not work I believe the problem might lies somewhere else (i.e. have you overridden layoutSubviews by any chance? or was the phone jailbroken?)
I highly doubt it'll be a UIKit bug though but it is totally possible.

Photos App Animation Advice

I have scoured the net for this question and have came up empty handed. I have an app that I'm making which I want the user to be able to view an image i have hooked up to the UIImageView to show fullscreen. Basically by tapping the UIImageView it would make the buttons and status bar disappear until image is tapped again. I know this is probably a simple animations block that i would throw in my viewdidload or where I call my image from. I'm just unsure where it goes.
here is where my image comes from if the helps.this is in my .m file
-(void)viewDidLoad {////Loads UIImageView from URL
todaysWallpaper.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://www.inkdryercreative.com/daily/archive/mondays/images/062-mondays-960x640-A.jpg"]]];
I have four buttons that appear on screen. i want it to resemble the feel you get in the native photos app when you look and a picture and everything else on screen dissolves. Any help or guidance would be great. I can send additional code if needed
CGRect *oldFrame = todaysWallpaper.frame; // store this somewhere for when you go back
CGRect *newFrame = [[UIScreen mainScreen] bounds];
[UIView animateWithDuration:0.5 animations:^{
todaysWallPaper.frame = newFrame;
}];

Unbalanced calls to begin/end appearance transitions for <GKModalRootViewController: 0xb7e450>

I give up on that point, I just can't figure out what is wrong and where...
Here is the problem: in my iPhone application using Cocos2d, I configured autorotation through a viewController; however, since, when Game center opens its view as the user taps on "Create new account" during the authentication, this view does not receive any touch, but the touch go to the game's view (which is hidden under the Game center view).
I have tried everything I thought about, but since I did not find any callback about this Game Center View, it is hard to find a way to correct this...
Here is the initialization of the game's view:
// Init the UI View Controller
//
viewController = [[SQViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;
EAGLView *view = [EAGLView viewWithFrame:[window bounds] pixelFormat:kEAGLColorFormatRGBA8 depthFormat:GL_DEPTH_COMPONENT24_OES];
[director setOpenGLView:view];
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
[view removeFromSuperview];
[viewController setView:view];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
I have tried many other things, commented every single line in this code, tried some others (such as setHidden:NO, bringSubviewToFront...), but the only results I could get were:
- Game display ok, Game Center ok, but no autorotate
- Game displayed in portrait (the view controller only allow landscape modes), Game Center ok, no autorotate
- Game not displayed (black screen), Game Center ok
And no way to make it all work together... The only clue I have is the title of this topic, "Unbalanced calls to begin/end appearance transitions for ." But since I do not call the Game Center view myself, I don't know what to do with this...
Anyone, any idea?
I've had the same problem while displaying game center leaderboards in my cocos2d built App ever since moving up to iOS 5.0. I've seen references elsewhere to this being caused by a sub viewcontroller losing focus on the parent viewcontroller, but I've been unable to verify that or get this resolved in my app either.
Good news is that I've run this thru instruments - No Memory Leaks. Also executed the same action repetitively with no apparent failures or ill effects.
So while this message is an annoyance, it doesn't appear (at least for now) to adversely affect the App.
This Error occurs when you try to push a viewController before previous ViewController is finished . Means you are trying to push 2 ViewControllers at the same time.

How do I detect orientation on app launch for splash screen animation on iPad!

Hi I have an app and I have two *.pngs for default splash screen:
Default-Landscape.png
Default-Portrait.png
What I want is to animate this default splash screen away when my app is loaded and ready to go.
To achieve this I would normally present an UIImageView with either default-landscape or default-portrait (depending on the device orientation), keep it on screen for a certain time and then animate it away.
My problem is that if I call [[UIDevice currentDevice] orientation] in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
The answer is always that the device is in portrait orientation even if I clearly have it in landscape. I tried this in simulator and on the device as well and the behaviour is the same.
Does anyone know a fix for this or maybe some other approach?
Thanks!
I had troubles with this and I solved it by making one image 1024x1024 and setting the contentMode of the UIImageView to UIViewContentModeTop, then using left and right margin autoresizing. So long as your portrait and landscape default images are the same layout then this will work fine.
Just to clarify here's what I used:
bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:SplashImage]];
bgView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
bgView.contentMode = UIViewContentModeTop;
To get around this problem I installed the splash image view inside of a view controller that allowed both orientations. Even though the device reported the wrong orientation at startup, the view controller seems to get the right one.
You can use UIApplication statusBarOrientation as follows:
if ( UIDeviceOrientationIsLandscape( [[UIApplication sharedApplication] statusBarOrientation] ))
{
// landscape code
}
else
{
// portrait code
}
Maybe you could show a blank view with black background at start time and place [[UIDevice currentDevice] orientation] into this view's viewDidAppear and start your splash screen from there?
Another solution would be to read the accelerometer data and determine the orientation yourself.
To know at start what is the orientation (UIDevice orientation don't work until user have rotate the device) intercept shouldAutorotateToInterfaceOrientation of your View Controller, it is called at start, and you know your device orientation.
There are certainly times when you want to transition from the loading image to something else before the user gets control of your app. Unless your app is really simple, going from loading image to landing page probably won't be sufficient without making the app experience really suck. If you ever develop a large app, you'll definitely want to do that to show progress during setup, loading xibs, etc. If an app takes several seconds to prepare with no feedback, users will hate it. IMO, there's nothing wrong with a nice transition effect either. Almost nobody uses loading screens the way Apple suggests to. I don't know which apps you looked at that showed the "empty UI" type loading screens they suggest. Heck, even Apple doesn't do that except in their sample code and none of my clients would find that acceptable. It's a lame design.
Only the first view added to the window is rotated by the OS. So if you want your splash screen to automatically rotate AND your main view is rotatable then just add it as a child of that view.
Here is my code for fading out the appropriate splash screen image:
// Determine which launch image file
NSString * launchImageName = #"Default.png";
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) {
launchImageName = #"Default-Portrait.png";
} else {
launchImageName = #"Default-Landscape.png";
}
}
// Create a fade out effect
UIImageView* whiteoutView = [[[UIImageView alloc] initWithFrame:self.window.frame] autorelease];
whiteoutView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
whiteoutView.autoresizesSubviews = YES;
whiteoutView.image = [UIImage imageNamed:launchImageName];
[[[self.window subviews] objectAtIndex:0] addSubview:whiteoutView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
whiteoutView.alpha = 0.0;
[UIView commitAnimations];
Note: You'll have to update it to support hi-res screens.
It sounds like you're not using the launch image the way Apple recommends in the iOS HIG. It specifically calls out that you should not use it as a splash screen, but rather as a skeleton version of your actual UI. The net effect is that your app appears to be ready just that much faster.
The suggestions that you could draw a splash screen yourself after the app has launching in viewDidAppear or similar also are missing the basic purpose of a launch image. It's not a splash screen. If your app is ready, let the user interact with it, don't waste their time drawing a splash screen.
From my five minute survey of Apple apps and third-party apps, everyone showed a portrait launch image, loaded the portrait version of the UI, and then rotated to landscape. It's been a while since programming on iOS, but I think this mirrors the order of the method calls -- first your app gets launched, then it is told to rotate to a particular orientation.
It might be a nice enhancement request to file with Apple though :)