PresentViewController With ModalPresentationStyle "UIModalPresentationFormSheet" IOS 8 - ios8

I am not able to set frame to PesentViewController with ModalPresentationStyle UIModalPresentationFormSheet in IOS 8. Same code works perfect in IOS 7. For all other ModalPresentationStyle, i am able to set frame. I am doing migration work from IOS 7 to IOS 8. If it is a IOS 8 bug i need a reference to produce.
FirstViewController *saleNotApprovedController = [[FirstViewController alloc]init];
saleNotApprovedController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:saleNotApprovedController animated:YES completion:^{
saleNotApprovedController.view.superview.frame = CGRectMake(100, 200, 500, 500);
}];
I tried to set frame in viewWillLayoutSubviews For PesentViewController. This code works while loading the page but when we change the orientation PesentViewController align to centre automatically.

Please use preferredContentSize to set view's frame.

Related

Can't figure out how to get UpSide down orientation to work in iOS 8?

I added UIScreen bounds code in AppDelegate.m for iPhone 6 and now device orientation for iPhone 6 won't work for Portrait/ Upside Down. Upside Down is what's not working in simulator and devices.
Code in AppDelegate.m
CGSize iosScreenSize = [[UIScreen mainScreen] bounds].size;
if (iosScreenSize.height == 667) {
UIStoryboard *iPhone6 = [UIStoryboard storyboardWithName:#"iPhone6" bundle:nil];
UIViewController *initialViewController =[iPhone6 instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
self.window.rootViewController = initialViewController;
[self.window makeKeyAndVisible];
}
When I included the above code the simulator and device for iPhone 6 doesn't detect Upside Down orientation. I also used nativeBounds and screenBounds, didn't work either for Upside Down orientation.
My code for device orientation...
-(NSUInteger)supportedInterfaceOrientations {
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
I have no idea what to do to get AppDelegate code to let UpSide Down orientation be detected for iPhone 6.
OK, finally figured this one out.
Then realized someone posted the answer here: Setting device orientation in Swift iOS
Go down to DaRk-_-D0G's answer.
I had to subclass my tab bar controller just to override that method. Very obnoxious .

How to restrict orientation of alertview on orientation change of device in ios8

In iOS 8 in my app when I changed the orientation of device at that time UIAlertview also get changed to respective Orientation.I want to restrict it.I want alertview fixed to be in Portrait mode.
In iOS8,system provide a new class UIAlertController replay UIAlertView and UIActionSheet,This is a FYAlertView that support iOS8 and iOS8 before use UIALertView and UIActionSheet https://github.com/wangyangcc/FYAlertManage
You can use this code it may help you .
- (void)didPresentAlertView:(UIAlertView *)alertView
{
[UIView beginAnimations:#"" context:nil];
[UIView setAnimationDuration:0.1];
alertView.transform = CGAffineTransformRotate(alertView.transform, degreesToRadian(90));
[UIView commitAnimations];
}

Resizing tableview height programmatically

I am using storyboard in xcode 4.5.
In my application there is 2 views, view1 and view2.
Each view has a tableview.
A navigation controller is connected to the views.
I am trying to change the height of the tableview depending on the size of the Iphone display.
I am using the following code:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// Verify if the screen is iphone 5
if ([[UIScreen mainScreen] bounds].size.height == 568){
// Resize table hight
CGRect tvframe = [_myTableView frame];
[_myTableView setFrame:CGRectMake(tvframe.origin.x,
tvframe.origin.y,
tvframe.size.width,
tvframe.size.height + 64)];
}
The problem is that the code has no effect when the application starts and view1 appears.
But when I move to view2 and then back to view1 the resizing takes effect.
I don't understand why the reszing doesn't take effect when the application starts.
Have you tried moving the code to ViewWillAppear? That should fix the problem.

How to develop for multiple iOS devices, i.e. multiple storyboards?

I am currently developing an app for the iPhone 3GS. The deployment target is set to 5.1 and I have created a rich storyboard with lots of segues and scenes. Last night I had the idea that I wanted to make the app available for the iPad, iPhone 4, and iPhone 5. I decided to create a separate storyboard for the different screen sizes / resolutions. Now I am not sure if this is the best practice, as I have just recently started reading about springs and struts on SO, so I don't know much information about it, but for my sake, I just wanted to launch a different storyboard when the application finished launching. However this desired effect is not happening.
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// ViewControllerWelcome *viewControllerWelcome = (ViewControllerWelcome *)[[ViewControllerWelcome alloc]init];
// NSManagedObjectContext *context = (NSManagedObjectContext *) [self managedObjectContext];
// if (!context) {
// NSLog(#"\nCould not create *context for self");
// }
//[viewControllerWelcome setManagedObjectContext:context];
// Do I need to declare my view controllers here?
// Pass the managed object context to the view controller.
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
if (iOSDeviceScreenSize.height == 480)
{
// Instantiate a new storyboard object using the storyboard file named iPhoneLegacy
UIStoryboard *iPhoneLegacy = [UIStoryboard storyboardWithName:#"iPhoneLegacy" bundle:nil];
// Instantiate the initial view controller object from the storyboard
UIViewController *ViewControllerWelcome = [iPhoneLegacy instantiateInitialViewController];
// Instantiate a UIWindow object and initialize it with the screen size of the iOS device
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Set the initial view controller to be the root view controller of the window object
self.window.rootViewController = ViewControllerWelcome;
// set the window object to be the key window and show it
[self.window makeKeyAndVisible];
}
if (iOSDeviceScreenSize.height == 968)
{
// Instantiate a new storyboard object using the storyboard file named iPhone4
UIStoryboard *iPhone4 = [UIStoryboard storyboardWithName:#"iPhone4" bundle:nil];
UIViewController *ViewControllerWelcome = [iPhone4 instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = ViewControllerWelcome;
[self.window makeKeyAndVisible];
}
// iPhone 5 1136 x 640
// iPad Legacy 1024 x 768
return YES;
}
When I try testing to see if the different storyboard file are loading in the Simulator, Simulator just loads the iPhoneLegacy storyboard.
Does this code only work for the physical devices, and do I need separate code for the Simulator?
Fist of all, DELETE YOUR EXTRA STORYBOARDS! You only need one for the iPhone and one for the iPad.
There is a simple way to make a single storyboard for all iPhone/iPod Touch sizes.
Keep only ONE storyboard for the iPhone screen size (including iPhone 5).
Make a #2x file for all of your images.
To switch between 3.5 and 4 inch size, Apple provides a button in the bottom right that looks like a rectangle with arrows pointing in or out - that button will switch between the 3.5 and 4 inch screen sizes.
That's it! No code is actually needed to make a single storyboard for each iPhone/iPod Touch.
For the iPad, you are going to need to create a new storyboard that is made for the iPad and you are going to need to update your UI code to make sure it's compatible with both iPhone and iPad screen sizes. Again, make sure to make #2x image sizes for the iPad as well.

MPMoviePlayerController doesn't play movie in full screen

I have a MPMoviePlayerController on my iPad app that works good when its frame is regular (not fullscreen).
When I tap the fullscreen button, the player goes fullscreen, but the movie stops. I perpetually see the title "Loading...", a black background, and the standard controls (back, play and next) disabled.
I declare an instance variable for the player:
MPMoviePlayerController *player;
In my implementation:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
player.shouldAutoplay = NO;
player.movieSourceType = MPMovieSourceTypeFile;
player.controlStyle = MPMovieControlStyleEmbedded;
player.allowsAirPlay = YES;
player.view.frame = CGRectMake(xPos, yPos, width, height);
[self.view addSubview:player.view];
[player prepareToPlay];
Do you have any idea? I'm using iOS 6 SDK, and I'm testing the app on iPad 6.0 simulator and a real iPad2 with iOS 6 beta (latest).
OMG!!!
I wrote...
[player stop];
in viewWillDisappear!!! How could I be so stupid?! No cake tonight...

Resources