Dynamically changed views in a full screen window in Xamain.Mac (monomac) - cocoa

I am trying to figure out a correct composition of views and subviews in Xamarin.Mac (monomac) application.
There are very little examples of Windows/Background View/Controls UI with Xamarin.Mac out there and those which I found (basically this project is the best documented one when it comes to Window/View composition) suffer from the same problem - its a static binding of a form Window -> Background view (bound in XCode) -> Controls under the View node. What's being displayed as controls on the view isn't dynamically added via C# and not even a separate view inside the background view.
What I need, is to create a Window, that has a background view that will be semitransparent and then have my application dynamically, depending of the app logic, inject different subviews to background view from C# code. I know that one can add a subview to a view in Xamarin.Mac, but when I try it in my case, the subview just isn't being shown:
GoFullscreen is where the window starts to transform:
private void GoFullScreen ()
{
// Set the window level to be above the menu bar
Window.Level = NSWindowLevel.Normal;
var backgroundView = new LeoBreakBackgroundView ();
backgroundView.SetBreakSubview (_currentBreakViewController);
Window.ContentView = backgroundView;
Window.ContentView.EnterFullscreenModeWithOptions (NSScreen.MainScreen, new NSDictionary());
// Show the window
Window.MakeKeyAndOrderFront (this);
}
At the point I call backgroundView.SetBreakSubview (_currentBreakViewController);
which is:
_currentBreakViewController = currentBreakController;
this.AddSubview (_currentBreakViewController.View);
I don't see the _currentBreakViewController.View being added to backgroundView, but the backgroundView is indeed added onto a window that goes fullscreen.
_currentBreakViewController is a NSViewController and LeoBreakBackgroundView you see in the first snippet is just an NSView without a controller.
Anyways, is it possible to control a View's subview dynamically from code in Xamarin.Mac?

Related

macOS/ Xcode / Swift 3, how can I have a storyboard scene inside a NSScrollView?

I am new to storyboards and just learning swift. My document based app has a main document view where all the action is (user mouse clicks, keyDown, etc). It's size can vary based on either user menu command or model state changes. It also has subviews that may come and go. This needs to be the document view of an NSScrollview.
This document view needs its own view controller.
Starting with the main storyboard if I add a scroll view to the main view controller view, I can set my custom view to be the document view. But there doesn't seem to be anyway to give it it's own view controller, within the storyboard paradigm.
Previously, (under objective c, if that matters), I was able to create my document view and it's view controller in a XIB, then in code assign this document view to the NSScrollview's document view.
Presumably, I could still do this in code in Xcode 8/Swift 3, but isn't there a way to do it with storyboards?
Added Later: I seem to get close to what I want by replacing the scroll view's document view with a container view. I'm using a centering clip view, and apparently the container view cannot have constraints, or it defeats the centering!
I can then drag a new view controller onto the container view. The new view controller and it's view can be my custom view controller and it's custom view.
This looks like it will work OK, so far, but it seems a bit of a kludge to me. Is this the standard way to embed a custom view controller with its view in an NSScrollView?

UIViewController as a popup in Xamarin iOS

In the current project,I am using an UIViewController with 2 text Fields and a text area.
Text fields are used as drop-down (custom logic) and based on drop-down selection information is displayed in text area for e.g. State and city are two drop down. On click of State drop down city data is populated in second drop down and on selection of city corresponding info is fetch and displayed in Text-area.
I have a requirement to move this logic to custom popup. Can anyone guide me how to achieve this with minimal changes in Xamarin iOS.
It would use UIPopoverController in this care. You already have a view controller with all the UI elements. You can use it as the DetailViewController so you don't have to change that much. Only it's size and the background. You can use it for both iPhones and iPads.
Here you have a sample project with source code:
https://developer.xamarin.com/samples/monotouch/Popovers/
Create a new UIViewcontroller in the storyboard, set the background colour of the main view to transparent, then create another view on top of that and put in any controls you want to display etc. then in the UIViewcontrollers init method add in the following:
public OverlayView(IntPtr handle) : base (handle)
{
ModalPresentationStyle = UIModalPresentationStyle.OverCurrentContext;
}
That way the background view that you've set as transparent won't just show black, it'll show in the context of the screen that called it, then you just present it as you would any other view, and add in some dismiss action events if you want it to pass data back etc. Hope this helps.

Xamarin set content view width to root view

I'm using Xamarin Auto Layouts with Storyboard on Visual Studio 2015.
I have a root view, Scroll View and Content View.
I want the application to only scroll on the y-axis but scale on the x-axis.
I want to do something like this.
Adding a view to a scroll view that will stretch to fill available width
Which is setting the width of the content view to the root view.
But using Xamarin this does not seem possible.
So in this example, if I run the application, I have to scroll to the right to see the right most label. I want all three labels to show up on the iPhone, by scaling down on the x-axis.
I have also tried using the "I" handle on the content view in storyboard UI Designer of Xamarin VS, but it doesn't identify the root view.
If it's not possible using storyboard, I will settle with code.
I have tried this.
public override void ViewDidLoad()
{
ContentView.Frame = new CoreGraphics.CGRect(ContentView.Frame.X, ContentView.Frame.Y, View.Frame.Width, ContentView.Frame.Height);
//ScrollView.TranslatesAutoresizingMaskIntoConstraints = false;
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
}
But it doesn't do anything to help me.
How can I scale the UI down on the X-axis while on top of a scroll view using Xamarin.ios?

Embedding Custom View with controls in NSScrollView

I'm trying to create a scrollable view with multiple controls inside it. For this I'm wrapping a Custom View control inside a NSScrollView and set the size of the custom view to about the same as the scroll view.
However if I place other controls inside the custom view in Interface Builder they don't appear in the custom view when running. Why is that?
If I place a button in a Custom View that is not wrapped in a NSScrollView it works but I want the custom view to be scrollable in case the window height is too small to show all controls.
After dragging in an NSScrollView in Interface Builder, look at the outline view in the xib window. You'll see that you now have a Bordered Scroll View, which contains a ClipView, which then contains a NSView.
a. Make sure your Custom View have been added as a subview to the NSView. If you add them at a higher level, you wont get the behavior you want.
or
b. Another option is to simply change the class of the NSView to your custom view class. Select the View that is inside the BorderedScrollView->ClipView, then click the 3rd tab from left (in the upper right of Xcode window) where you can type in your custom class name in the field labeled "Class".

NSWindowController/NSViewController "Presentation" setting in Storyboard

What exactly does the Presentation option(in Attribute Inspector) do in StoryBoard for Cocoa.
It gives two options to select from
Single
Multiple
P.S When googled the title, results are related to powerpoint presentation
The presentation style affects "Show" segues. Possibly it affects other segues too, but I only tested a Show segue. I tested on OS X 10.10.5 (Yosemite) with Xcode 7.1.1.
If a window controller's presentation style is "Multiple" (the default), then a Show segue to the window controller always loads a new instance of the window controller from the storyboard. This means that you can end up with multiple instances of the window controller at once, each with its own window on the screen. By default those windows will stack on top of each other, so it won't be obvious what happened until you move or close one.
If a window controller's presentation style is "Single", and an instance of the window controller has already been loaded from the storyboard, and that window controller still exists (presumably because its window is still on screen), then a Show segue to that view controller will not create a new instance. Instead, the Show segue will bring the existing window controller's window to the front.
This behavior is useful if you want behavior like, say, Xcode's Devices window, where there can only be one such window. You create a "Devices" menu item in the Window menu in your storyboard, and connect it to the Devices window controller in the storyboard with a Show segue. Set the Devices window controller's presentation style to Single. Now the menu item will never create a second Devices window controller if one already exists.
You'll probably want to somehow set the window's excludedFromWindowsMenu property to true, so it doesn't appear twice in the Window menu (because by default it appends itself to that menu). You could, for example, use a subclass of NSWindowController that sets it:
class DevicesWindowController: NSWindowController {
override func windowDidLoad() {
super.windowDidLoad()
window?.excludedFromWindowsMenu = true
}
}
View controllers also have a presentation style, because you can also connect Show segues to view controllers. A Show segue connected to a view controller automatically creates a window controller to contain the view controller at runtime. The window controller's presentation style is effectively set to the view controller's, so you get the same singleton behavior if you set the view controller's presentation to Single.
As far as I can tell, the storyboard setting has no corresponding public property or method you can use in code.
If you connect the Show segue to a storyboard reference (new in Xcode 7), then the segue ignores the presentation style of the destination window controller, and acts as if it were "Multiple". This happens even if the destination is actually in the same storyboard as the reference.

Resources