Xamarin IOS storyboard scrollview doesn't scoll - ios

I'm trying to create a signup form in a storyboard in the Xamarin Studio editor, but I can't get i to scroll.
I have set AutoLayout to false.
My Document outline can be seen at the picture:
And in my CreateUserViewController I have the following:
public override void ViewDidLoad ()
{
ScrollSignup.ContentSize = new CoreGraphics.CGSize (1000, 1000);
base.ViewDidLoad ();
}
The view is set to 700 in height

Solved it myself. Just needed to a a view in the scroll view and let that view contain the elements

Related

Xamarin iOS large tittle scroll velocity snapping issue

I am using Xamarin.Forms version 5.0 to develop an app for iOS 15. I am struggling to smooth the large title scroll transition. My problem is outlined on this question: iOS 11 large navigation bar title unexpected velocity
According to the above link, It seems like a fairly simple solution on Swift but I am struggling to do this using Xamarin.iOS.
Using a custom renderer, I have the following settings:
ExtendedLayoutIncludesOpaqueBars = True;
EdgesForExtendedLayout = UIRectEdge.Top;
AutomaticallyAdjustsScrollViewInsets = true;
NavigationController.NavigationBar.PrefersLargeTitles = true;
NavigationItem.LargeTitleDisplayMode = UINavigationItemLargeTitleDisplayMode.Automatic;
NavigationController.NavigationBar.Translucent = true;
I have tried modifying the constraints of my ScrollView by setting them to the constraints of the View. View.Superview is null for this page and would not allow me to change those constraints.
I have tried all sorts of different combinations of settings.
I have tried changing my ScrollView to a TableView.
I know I could make a custom navigation bar that could simulate this transition but I am trying to use native iOS settings and UI designs.
One of the answers on this question suggest the only way to get the smooth scroll transition is to use a UITableViewController instead of a UIViewController with a UITableView inside. Is this possible on Xamarin? I haven't found a way to use UITableViewController when designing the UI in Xaml. Even if I can change to a UITableViewController, will I be able to set the constraints correctly in the renderer?
Are there any other things I should try?
Thank you for any responses.
Try to find the ScrollView and change its constraints .
[assembly: ExportRenderer(typeof(ContentPage), typeof(MyBarRenderer))]
namespace FormsApp.iOS
{
internal class MyBarRenderer : PageRenderer
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
ExtendedLayoutIncludesOpaqueBars = true;
foreach (UIView view in View.Subviews)
{
if (view is UIScrollView sc)
{
NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] {
sc.TopAnchor.ConstraintEqualTo(View.TopAnchor),
sc.LeftAnchor.ConstraintEqualTo(View.LeftAnchor),
sc.BottomAnchor.ConstraintEqualTo(View.BottomAnchor),
sc.RightAnchor.ConstraintEqualTo(View.RightAnchor),
});
}
}
}
}
}
Refer to
iOS 11 large title navigation bar snaps instead of smooth transition

Custom UIInputView presented on inputAccessoryView not respecting height constraint on iPhone X

I am building a chat application that has a floating text input field at the bottom of the screen (similar to the iMessage app).
I've achieved this by creating a ChatInputViewController which is a subclass of UIInputViewController, which contains a UIInputView with a textView for input.
In my main ChatViewController, I then override the following properties to present my custom UIInputViewController:
class ChatViewController: UIViewController {
override var inputAccessoryViewController: UIInputViewController? {
return chatInputViewController
}
override var canBecomeFirstResponder: Bool {
return true
}
...
}
Here's the issue: I also have a custom input view which is presented when the user taps on the help icon. The custom input view is laid out using Autolayout and has an explicit height constraint set to be equal to the height of the keyboard. When presented, this view swaps out with the keyboard in place. I am doing this by setting the inputView property of the textView and then calling textView.reloadInputViews(). This works as intended on all devices except the iPhone X, where instead the inputView is expanded to cover the entire screen.
There are no autolayout constraints logged in the console. Both the ChatInputViewController and HelpInputViewController have allowSelfSizing enabled on their inputViews and translatesAutoresizingMaskIntoConstraints disabled. Any ideas would be greatly appreciated.

UISplitViewController Master Content Width

I have a UISplitViewController in my application (MvvmCross / Xamarin iOS) and for some reason I cannot get the content to respect the dimensions of the available view areas.
In the situation shown in the screenshot the master view is hosting a UIViewController with a TableView inside. All the layouts are done with constraints and work fine on their own when running in an iPhone emulator.
As soon as I switching to running on an iPad some custom code I have in my presenter shows this same view in the master panel of a UISplitViewController but in this situation the constraints seem to be ignored and I end up with a view that looks like this:
As you can see the right hand side of the table cell is now way off the viewable area of the master panel of the UISplitViewController.
Both the UITableView and the UITableCell both use View.Frame as their initial size (I've tried View.Bounds as well).
How can I get the cells and / or table to respect the bounds of the UISplitViewController available space?
Thanks to Cheesebarons question I found my solution (cause).
I have a set of methods in a helper class that I use to generate my "default" UIViews.
One of these methods creates my default UITableView:
public static UITableView CreateDefaultTableView(CGRect rect, UITableViewStyle style)
{
var tv = new UITableView(rect, style)
{
AutoresizingMask = UIViewAutoresizing.FlexibleHeight,
SeparatorStyle = UITableViewCellSeparatorStyle.SingleLine,
SeparatorColor = IosConstants.DefaultTableSeparatorColor,
BackgroundColor = IosConstants.DefaultViewBackgroundColor
};
return tv;
}
Changing:
AutoresizingMask = UIViewAutoresizing.FlexibleHeight,
To:
AutoresizingMask = UIViewAutoresizing.All,
Schoolboy error!

Add a UIView to a ScrollView for paging

How can I have a UIScollView content be the content from a UIView? I want to design the app layout in a UIView and then lay that view into a UIScrollView that is connected to a UIPageControl for pagination. So when the user swipes to the side, the next view is displayed. I have a sort of idea on how I would accomplish this, but I want to get it right without wasting a lot of time.
Heres my DetailViewController:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using UIKit;
using Foundation;
using CoreGraphics;
using CloudKit;
namespace RecordStorePro
{
public partial class DetailViewController : UIViewController
{
public Record DetailRecord { get; set; }
public DetailViewController (IntPtr handle) : base (handle)
{
}
public void SetDetailRecord (Record record)
{
if (DetailRecord != record) {
DetailRecord = record;
// Update the view
ConfigureView ();
}
}
void ConfigureView ()
{
// Update the user interface for the detail item
if (IsViewLoaded && DetailRecord != null) {
//label.Text = DetailRecord.Album;
}
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
NavigationItem.SetLeftBarButtonItem (new UIBarButtonItem(UIBarButtonSystemItem.Stop, (sender, args) => {
NavigationController.PopViewController(true);
}), true);
ConfigureView ();
//this.scrollview.BackgroundColor = UIColor.Gray;
// set pages and content size
scrollview.ContentSize = new SizeF ((float)(scrollview.Frame.Width * 2), (float)(scrollview.Frame.Height));
//this.scrollview.AddSubview ();
this.scrollview.Scrolled += ScrollEvent;
}
private void ScrollEvent(object sender, EventArgs e)
{
this.pagecontrol.CurrentPage = (int)System.Math.Floor(scrollview.ContentOffset.X / this.scrollview.Frame.Size.Width);
}
public override void DidReceiveMemoryWarning ()
{
base.DidReceiveMemoryWarning ();
// Release any cached data, images, etc that aren't in use.
}
}
}
So when I swipe the screen, I want a subview that contains some labels and textfields to come in and replace the original labels and textfields. It works properly so far except I can't figure out how to add the subview, and make it size appropriately to different screen sizes.
EDIT
Heres the problem Im facing now, the views laying in the ScrollView act funny and are about 44f too tall so they let me drag up and down. i tried setting all kinds of constraints as well as manually setting them to -44 smaller with no help. heres a picture of the problem now:
Heres the screenshot of my constraints set.
View A:
View B:
ScrollView:
Nib view:
To do this, you might want to try these steps:
The view that shows the first page will be called View A. The view that shows the second page will be called View B.
Add both views to the Scroll View.
Control-drag from View A to the Scroll View in the sidebar.
Hold down Shift and select Top Space to Superview, Bottom Space to Superview, and Leading Space to Superview. Next, press Return to add those constraints.
Make sure those constraints’ constants are set to 0.
Control-drag from View B to the Scroll View in the sidebar.
Hold down Shift and select Top Space to Superview, Bottom Space to Superview, and Trailing Space to Superview. Next, press Return to add those constraints.
Control-drag from View A to View B in the sidebar.
Select Horizontal Spacing. Make sure its constant is 0 and its Second Item is View A.Trailing and its First Item is View B.Leading.
Control-drag from View A to View B in the sidebar. Select Equal Widths. Make sure the Constant is 0.
Control-drag from View A to the Scroll View in the sidebar. Select Equal Widths. Make sure the constant is set to 0.
In the inspector, check “Paging Enabled.”
Adding subScrollView with no pagingEnabled to each page and controls into subScrollView works! If you add controls directly to scrollview with paging enabled, it seems gesture recogniser's first responder is always scrollview so your controls never gets the event and behave like a disabled!
UIScrollView has a property called “pagingEnabled”
In Interface Builder, resize the scroll view to allow for some space below it for the page control. Next, drag in a UIPageControl from the library, centered below the scroll view. Resize the UIPageControl to take up the full width of the view.

If UITextView is first sub-view then a big space will appear between the top of the view and the start of the text

It appears that like in native Xcode, in Xamarin studio for ioS if your first sub-view in a view hierarchy is a UITextView, then adding a top-layout constraint to this view will cause a large block of empty space to appear at the top of the scroll view.
This is similar to the Xcode version of the question here
iOS 7 UITextView vertical alignment
I solved this programmatically by adapting
Tanguy-G's answer for native Objective-C by setting AutomaticallyAdjustsScrollViewInsets to false in the constructor of my view controller.
public MyLovelyViewController (IntPtr handle) : base (handle)
{
this.AutomaticallyAdjustsScrollViewInsets = false;
}
EDIT: If you are setting any other aspects of the text view in question programmatically, make sure to call
this.AutomaticallyAdjustsScrollViewInsets = false;
after any other adjustments, otherwise the space will reappear, e.g:
confirmSummary.Editable = false;
confirmSummary.Selectable = false;
this.AutomaticallyAdjustsScrollViewInsets = false;
(I did this in the override of ViewDidLoad)

Resources