I am using modalPresentationStyle of type UIModalPresentationFormSheet to show my view.I want specific size of the view so using preferredContentSize which working in iOS 8 and showing exact how I wanted but same breaks for iOS 7 it's come as full sheet.View size changed.
Where as I wanted like below image
Any idea?
Please check below conditional code for iOS 8.x and iOS 7
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8.0"))
{
modalController.preferredContentSize = CGSizeMake(frameSize.x, frameSize.y);
}
else
{
modalController.view.superview.frame = CGRectMake((screenWidth - frameSize.x)/2, (screenHeight - frameSize.y)/2, frameSize.x, frameSize.y);
}
Hope this will help you.
Related
I am developing a game where a background is moving at the back. I sat the background hight using the below code. It is working fine with iPads but with iPhones it is not taking the proper hight of the screen; instead it is in the middle of the screen with almost half the hight of the screen! The application is only working in portrait orientation. This is for xCode 8 & SWIFT 3
Please check below the code I am using for the background
hight:
let screenSize: CGRect = UIScreen.main.fixedCoordinateSpace.bounds
background1.size.height = screenSize.height
Thanks in advance
I have resolved the issue but using a (workaround) rather than resolving the root cause as I could not identify it.
First I have noticed that when sizing the hight of the screen I have 2 conditions:
below code will work with all iPhones but not iPads:
background1.size.height = self.frame.height
below code will work with all iPads but not iPhones:
background1.size.height = screenSize.height
So since the minimum hight of screen of iPads is 1024; I used the below code to first check if it is iPad use condition 2 and if iPhone use condition 1 as follow:
let screenSize: CGRect = UIScreen.main.bounds
if screenSize.height < CGFloat(1024) {
background1.size.height = self.frame.height ////for iphone
} else {
background1.size.height = screenSize.height ////for ipad
}
I am not sure what your case is.But it happens in iPhone 5+ devices due to launch screen size.Normally it behaves like iPhone 5 screen size even with iPhone 6,iPhone 6+.
Now the soultion.
1.You can use the default launch screen storyboard to avoid the problem.
2.You have to add every sizes for iPhone screen size (320*480,640*960,640*1136,768*1334,1242*2208).please add also iPhone 7,7+ sizes too.
3.You can use asset Catalogs for launch screen.
If thats the case for you please use above solution.It should work.
I am building an iOS Today widget, and while testing for iOS 10, I see a "Show More" / "Show Less" button on the top right of the widget header. How can I remove this button? I am using Objective-C.
In iOS 10, as far as I know, the show more option is new and we cannot remove it, but we can modify it as needed.
The following code will allow you to automatically size the Today widget. Just change the table or collection view or whatever you used in your project.
static CGFloat padding = 25.0;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// This will remove extra separators from tableview
self.articleTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
// Add the iOS 10 Show More ability
[self.extensionContext setWidgetLargestAvailableDisplayMode:NCWidgetDisplayModeExpanded];
}
- (void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode withMaximumSize:(CGSize)maxSize {
if (activeDisplayMode == NCWidgetDisplayModeCompact){
// Changed to compact mode
self.preferredContentSize = maxSize;
}
else{
// Changed to expanded mode
self.preferredContentSize = CGSizeMake(self.articleTableView.contentSize.width, self.articleTableView.contentSize.height + padding);
}
}
In viewDidLoad you can set the largest available display mode.
[self.extensionContext setWidgetLargestAvailableDisplayMode:NCWidgetDisplayModeCompact];
This will remove the Show More/Less button, but it may not be what you want. The maximum allowed size for the compact view is fairly small.
You can implement:
-(void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode withMaximumSize:(CGSize)maxSize
to update your preferredContentSize. The maxSize parameter will be the maximum allowed size for the activeDisplayMode.
-[NCWidgetProviding widgetActiveDisplayModeDidChange:withMaximumSize:]
Is probably what you're looking for, I would reference this
Sadly you cannot hide it and should conform to the
widgetActiveDisplayModeDidChange:withMaximumSize:
widgets that doesn't show this control were not build for iOS10
I know the original post mentions using objective-c
but in the event anyone needs the swift answer, here it is
override func viewDidLoad()
{
super.viewDidLoad()
self.extensionContext?.widgetLargestAvailableDisplayMode = .compact
}
When set to compact, the app will only support compact mode i.e. show less/show show buttons/functionality will be gone.
here's some documentation for more info
Placing this line of code inside the widgetActiveDisplayModeDidChange delegate method solved my problem.
[self.extensionContext setWidgetLargestAvailableDisplayMode:NCWidgetDisplayModeExpanded];
If you wanna hide the show more/ show less option replace NCWidgetDisplayModeExpanded with NCWidgetDisplayModeCompact.
- (void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode
withMaximumSize:(CGSize)maxSize {
[self.extensionContext setWidgetLargestAvailableDisplayMode:NCWidgetDisplayModeExpanded];
}
I have realised my app is showing a different aspect on the navigation bar for iOS 9.
My app is landscape view always, and I am using a custom height:
- (CGSize)sizeThatFits:(CGSize)size {
[super sizeThatFits:size];
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
CGSize newSize = CGSizeMake(screenWidth, VFSNavigationBarHeight);
return newSize;
}
It looks perfect on iOS 8 and iOS 7, but the content is not vertical aligned on iOS 9.
This is how it looks on iOS 7 and 8.
And this is exactly the same code running on iOS 9.
As you can see iOS 9 is moving down the content of the navigation bar, and I'm not sure why. Any idea? Thanks
Hi I create app for ios 5 and 6, I need to reposition my button depend on interface orientation. Problem is that:
ios 5: it return UIInterfaceOrientationLandscapeRight while ios 6 it return UIInterfaceOrientationLandscapeLeft.
So I cannot reposition my button correctly
I don't know how to deal with this, or I need to change something in setting.
Thank you for your help!
I have no idea why the orientations are different.But maybe you can solve the problem like this
UIDevice *device = [UIDevice currentDevice];
NSString *tem = device.systemVersion;
if ([tem intValue]>=6){
}
else if{
}
I was developing a UISplitView app by using Xcode 4.6 when I left iOS6 I had design:
Now I migrate to new Xcode5 and now I have this design:
UINavigationBar overlaps completelly my UISearchBar...
Leo Natan told me about using a iOS 6/7 Deltas but since I'm creating and adding my UISplitViewControllers programmatically,
this may doesn't work I need to set the iOS 6/7 programmatically but I don't know how, any help I'll appreciate
In iOS 7 there are now extended edges, and that's why navigation bar overlaping the searchbar. You can set self.edgesForExtendedLayout = UIRectEdgeNone; this is UIVewControlelr property.
You can also make checks depending on version of iOS and You can do things depending on current version of iOS in device.
NSString *version = [[UIDevice currentDevice] systemVersion];
int ver = [version intValue];
if (ver < 7){
//iOS 6 work
}
else{
//iOS 7 related work
}
Also, you can use NSFoundationVersionNumber
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
// > iOS7
} else {
// <= iOS6
}
You can create a makro for solve this problem.
it is useful for me.
#define iOS7Delta (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0 ) ? 20 : 0 )
If the view's embedded in a UINavigationController -
simply untick "Translucent" for your root navigation bar.
In storyboard, select Navigation Controller Scene,
next select Navigation Bar and in Attributes Inspector (Utilities - 4 tab)
untick "Translucent"