I have a viewController and I have
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
why I read w and h as 320 and 480 on its viewDidLoad for width and height, instead of 480 and 320, respectively, when iPhone is landscape? (see below)
- (void) viewDidLoad {
CGFloat w = self.view.bounds.size.width; // 320???
CGFloat h = self.view.bounds.size.height; // 480 ??
}
What am I missing?
thanks.
Be careful, it is possible you have run in to perhaps the most famous bug on the platform:
iPhone app in landscape mode, 2008 systems
This is a bug that catches a lot of people. Notice that on that question, one of the responses has 22 votes - that response is actually completely, totally, 100% wrong.
That shows some of the confusion on the issue.
Be sure to check out everything on there and all the links, eg:
"An important reminder of the ADDITIONAL well-known problem at hand here: if you are trying to swap between MORE THAN ONE view (all landscape), IT SIMPLY DOES NOT WORK. It is essential to remember this or you will waste days on the problem. It is literally NOT POSSIBLE. It is the biggest open, known, bug on the iOS platform."
Did you try to obtain the values in viewDidAppear? With viewDidLoad the view was not actually rendered and so it might be still in portrait.
I always have this problem...
I think that all views must render in portrait mode and then switch to landscape. Its a bitch, but the best way to manage this is to use UIViewAutoreizingMasks on all sub-views, that way they'll layout how you want them to.
Related
When using iPhone app on a iPad, the keyboard extension can only know the screen size of an iPad, but actually I should know it's like running on an iPhone, and get a size like an iPhone.
My current code runs in a iPhone app on iPad look like this:
In viewDidAppear of UIInputViewController, I can actually get the frame of self.inputView, that is 320 in this case.
However, self.view and self.inputView's frame are both CGRecteZero in viewDidload or viewWillAppear, and that's actually why we should set keyboard height only after [super viewDidAppear].
The actual size of the keyboard view(self.view.frame) can be checked right after invoking [super viewDidLayoutSubviews] in viewDidLayoutSubviews of UIInputViewController. It is the 1st place to check the size and much faster than viewDidAppear.
Your Keyboard extension should be universal, if so then you can get device type (iPhone/iPad) by using below code.
let isPad = UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad
It may possible that you are using below method to get screen bounds
UIScreen.mainScreen().bounds.size
This method gives device's whole height, width in keyboard extension.
You can use nested condition by using above two condition to solve your problem.
I am following MessagesTableViewController and there is method of starching of UIImage for bubble view to strech as per text size. It is working fine with older ios version but in ios7, it is displaying light color borders as we set UIEdgeInsetsMake as below.
+ (UIImage *)bubbleDefaultIncoming
{
return [[UIImage imageNamed:#"bg-chat-white.png"] makeStretchableDefaultIncoming];
}
- (UIImage *)makeStretchableDefaultIncoming
{
return [self resizableImageWithCapInsets:UIEdgeInsetsMake(15.0f,20.0f, 15.0f, 20.0f)
resizingMode:UIImageResizingModeStretch];
}
Here i attached 2 snapshot for ios6 and ios7 which describe how bubble View is behaving strange with ios7 though code is same.
and
Someone has also same issue and reported in GITHUB HERE
I reviewed code so much and it seems that there is issue with resizableImageWithCapInsets in ios7. It generates borders as we set UIEdgeInsetsMakein the method.
Anyone has idea or solution to remove the borders from bubble view and make same as ios6 bubble view?
Any help would be appreciable. Thanks in advance.
Transparent lines are added in iOS 7 when the width or height is a number with floating point. As a workaround, you can round this numbers
You need to ensure that the CGRect you are drawing the image into is an even number and not a number with a floating point.
In addition to this if you have a UITableView with TabViewCells that have different heights you also need to need to ensure those cells all have heights that are an even number and not a number with a floating point.
i can confirm that both answers are right, but since you are using the same framework as me i going to give you a snippet to help.
just floor or ceil the size of the bubble and you are good to go.
- (CGRect)bubbleFrame
{
CGSize bubbleSize = [JSBubbleView bubbleSizeForText:self.text];
return CGRectMake((self.type == JSBubbleMessageTypeOutgoing ? floor(self.frame.size.width - bubbleSize.width) : 0),
kMarginTop,
floor(bubbleSize.width),
floor(bubbleSize.height));
}
edit: the position too need to be rounded up or down, since the kMarginTop already is you only need for it when it's a outgoing bubble. peace
I've just added SKStoreProductViewController and presented it from my own UIViewController.
If I rotate device to landscape mode - only header fits the width, other parts are truncated
....
NSDictionary *parameters = #{SKStoreProductParameterITunesItemIdentifier:[NSNumber numberWithInteger:[productID integerValue]]};
[self.storeViewController loadProductWithParameters:parameters
completionBlock:^(BOOL result, NSError *error) {
if (result)
{
[presentingViewController presentModalViewController:self.storeViewController
animated:YES];
}
handler(result);
}];
Is it possible to adapt "product page" in landscape mode, to make it looks good?
Env: iPhone 4S IOS 6.0.1
Yes, it's very poorly implemented.
I'm actually surprised that this has managed to pass any QA whatsoever on Apple's part.
When you press on one of the screenshots, it displays a, let's say, "detail" screen, where the scroll view still cuts off the images and the images themselves aren't centered on the screen, which leads to them being half obscured.
I've logged a bug in Apple's bug reporting system and I encourage you to do the same, as that'll increase the chance that Apple actually fixes it.
https://developer.apple.com/bugreporter/
I believe that I did everything necessary to change my app for ipad (was for iphone at start). I can toggle the build status to either iphone (only), ipad (only) or iphone/ipad - and the app launches either in ipad or iphone simulator. I can do that forth and back at will.
I added the idiom to check for ipad and basically for one of my xib, instead of using the string of my xib to create the controller, I use the one for the ipad. So it is a new xib for ipad with all same graphical objects ( enlarged ;-) ) . I added the callbacks to function correctly with IB.
I can see everything fine and arrive on my new ipad view BUT when I click on one of my buttons... nothing happened like if my callbacks don't work. It is very surprising and actually I have no idea where to look as I compared most of the parameters between my iphone and ipad view and they are identical as far as I can see.
It must be something damn obvious so if one of you had the same issue and it was a very simple answer ... I guess that would be what I missed!
Thanks for your help in advance
Cheers,
geebee
EDIT1: Some code as requested
at start I have that to decide either way:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
examTFVC_NIB=#"ExamTFViewController-iPad";
}
else
{
examTFVC_NIB=#"ExamTFViewController";
}
Then to go to the right view:
ExamTFViewController *examTFViewController = [[ExamTFViewController alloc]
initWithNibName:globals.examTFVC_NIB bundle:nil];
But I have no problem loading the correct XIB. The issue is really the callback functions not being called...
Thanks for the help.
EDIT2:
I also realised that calling the extension of the xib xxx~ipad allows to avoid the example code above. And it works - but still no function can be called.
EDIT3:
IMPORTANT FINDING: if I move my buttons higher and on the left of the screen: they work! So it seems that the functions are called if the event are in the region of an iphone screen although I am on an ipad screen. I guess know it would be more obvious to find the issue! thanks for any help – geebee just now
ANSWER
iPad touch detected only in 320x480 region
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// to correct region size
CGRect rect = [[UIScreen mainScreen] bounds];
[window setFrame:rect];
// now, display your app
[window addSubview:rootController.view];
[window makeKeyAndVisible];
}
** OR OTHER SOLUTION **
Check the full screen at launch checkbox - only present in the ipad xib MainWindow
finally solved - with 2 methods - programmatically or via IB - in the edited section of the post.
Once again I've searched for about 45 minutes for an answer to this question and I thought I might have found the answer but then the situation I was reading wasn't exactly like the one I'm running into.
when I add my view it seems that it's not completely covering the window I was able to get rid of the status bar at the top but there is a section of space at the bottom that the view is not covering
alt text http://img177.imageshack.us/img177/8844/picture1zjv.png
as you can see from the screenshot there is an orange bar...it's orange because I know what it actually is under there (it's the viewController's view but everything I try I can't seem to get the added view to cover the screen.
this is the only code that's run
(void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:mainMenu];
}
Any help would be appreciated.
There are a few things that might be going wrong:
Your frame might be too short. In viewDidLoad: you can add a debug statement to check its height:
NSLog(#"Height is %f", self.view.frame.size.height);
It looks like you want that value to be 480, the full height of the screen.
Your origin might be too high. Similarly check your y offset:
NSLog(#"y origin is %f", self.view.frame.origin.y);
It looks like you want that value to be 0.
The origin of your superview might be too high. Assuming you this view only has one superview, this code will help check the absolute coordinates of your view's origin:
CGPoint absoluteOrigin = [self.view convertPoint:self.view.frame.origin
toView:self.view.superview];
NSLog(#"y origin in superview is %f", absoluteOrigin.y);
You can just tag on a few extra .superview's to find out the coordinates in terms of the prior views.
By the way, instead of just using 480 as a magic number in your code, you might want to do something like this to get the full height:
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
CGFloat screenHeight = appFrame.size.height;
The applicationFrame property takes into account whether or not the status bar is displayed.
You should post your code, but in general, you can make a UIView fill the screen as follows:
UIView *foo = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
And you can set the frame later:
foo.frame = CGRectMake(0,0,320,480);
To fill the screen, you should use a 320 x 480 Rectangle, at origin (0,0). That's what that CGRectMake function above creates.
I've had this problem before, I fixed it by just moving the view down 20 pixels...
When you use interface builder it has that nifty little "simulate status bar" or "simulate toolbar" feature but I think its kind of finnicky.
Both Andrew and Tylers answers should work though, no shame in doing things programmatically :). If you are creating the stuff in interface builder, just do Andrew's second line though, don't need to reinitialize.
Ok, well I figured it out and now I feel kind of stupid...I went back to IB and realized that the height of each view was set at 460 and not 480...you guys did give me a bunch of good information and I appreciate it all. I wish I could mark them all as answers.
Thank you again,
BWC