UIModalPresentationFormSheet

There’s a style of presentation that some iPad apps use which displays certain content in a window (sheet) which is not full screen. UIModalPresentationFormSheet is described here.

This is useful in cases such as app settings, for example, where using the entire screen would space out the content too much, leaving large gaps between settings and values. I also read somewhere that views setup as UIModalPresentationFormSheet will automatically display full screen on smaller devices, ie iPhones. So you get the best of both worlds depending on screen size.

Here’s an example from one of the apps installed on my iPad:

I’m not hopeful … but I was wondering whether anybody had tackled this in Xojo?

Hi Jason,

Yes I managed this in my apps.

I use Jason King’s iOSKit and added a code to a module.

This is the code I use.

  1. Show the View as modal on an iPad, or regular on an iPhone

[code] //Show settings
Dim v As New vSettings
If isIPad Then
CreatePopover(self, v, UIKit.UIViewController.UIModalPresentationStyle.formSheet)

Else
  self.PushTo(v)
End If[/code]
  1. Creates a popover form sheet for iPad

[code]Public Sub CreatePopover(parentView as iOSView, popView As iOSView, style as UIKit.UIViewController.UIModalPresentationStyle = UIKit.UIViewController.UIModalPresentationStyle.popover, sourceControl as iOSControl = nil)

Dim navController As new UIKit.UINavigationController(popView)
navController.modalPresentationStyle = style

//First we present the view controller
parentView.PresentViewController(navController, true, nil)

//Then we set the sourceRect for Popover
if style = UIKit.UIViewController.UIModalPresentationStyle.popover then
declare function popoverPresentationController_ lib UIKitLib selector “popoverPresentationController” (obj_id as ptr) as ptr

Dim popController As UIKit.UIPopoverPresentationController = new UIPopoverPresentationController(popoverPresentationController_(navController))

#if Target32Bit
  declare function frame_ lib UIKitLib selector "frame" (view as ptr) as NSRect32
#Elseif Target64Bit
  declare function frame_ lib UIKitLib selector "frame" (view as ptr) as NSRect64
#Endif
Dim rect As Foundation.NSRect = frame_(sourcecontrol.Handle)




//Need to calculate an offset is there is a navigationBar
Dim offset As Double
if parentView.NavigationBarVisible then
  declare function navigationBar lib "UIKit" selector "navigationBar" (obj_ref as ptr) as ptr
  declare function navigationController lib "UIKit" selector "navigationController" (viewController as ptr) as ptr
  dim navigationControllerRef as ptr = navigationController(parentView.ViewControllerHandle)
  dim navBar as ptr = navigationBar(navigationControllerRef)
  
  Dim rect2 As Foundation.NSRect = frame_(navBar)
  offset = rect2.rsize.h
end if


popController.sourceView = new uikit.uiview(sourceControl.Handle)
popController.sourceRect = new Foundation.NSRect(0, rect.origin.y-offset, rect.rsize.w, rect.rsize.h)


//Set the size
navController.preferredContentSize = new Foundation.NSSize(200, 400)

end if

End Sub
[/code]

I can’t exactly remember which classes/enumarations/constants I added to iOSKit, if you could let me know which parts of that code doesn’t run, I’ll be able to share the missing parts.

@JrmieLeroy feel free to submit pull request to iOSKit with new features and I’ll add them

Thank you so much @JrmieLeroy !

As you expected, a few lines fail due to some missing pieces:

Until iOSKit is updated on GitHub this should help:

Public Enum UIModalPresentationStyle fullscreen = 0 pageSheet formSheet currentContext custom overFullScreen overCurrentContext popover none = -1 End Enum

[code]Public Property modalPresentationStyle as UIModalPresentationStyle
Get
declare function modalPresentationStyle_ lib UIKitLib selector “modalPresentationStyle” (obj_id as ptr) as UIModalPresentationStyle
Return modalPresentationStyle_(self)
End Get

Set
declare sub modalPresentationStyle_ lib UIKitLib selector “setModalPresentationStyle:” (obj_id as ptr, modalPresentationStyle as UIModalPresentationStyle)
modalPresentationStyle_(self, value)
End Set

End Property
[/code]

And import this file into iOSKit/Foundation module https://www.jeremieleroy.com/upload/UIPopoverPresentationController.xojo_code

I hope that is all that is missing.

@JrmieLeroy let me know when you submit a pull request and I will happily merge it in.

Thanks @JrmieLeroy . It’s better but there are still a few errors. Perhaps I’ve put the computed property modalPresentationStyle in the wrong class? I put it in the UIKit.UINavigationController class as that seemed to resolve one error but it looks as though I need another property in UIKit.UIViewController called UIModalPresentationStyle? Is that the same property as the one in UIKit.UINavigationController but just renamed?