Xamarin iOS 7.1 - UIScrollview 不滚动
Xamarin iOS 7.1 - UIScrollview not scrolling
我正在 Xamarin 中开发一个应用程序,我在其中使用 UIScrollView 控件,该控件在 iOS 8.4 中滚动得很好;但是,当我在 iOS 7.1 中对其进行测试时,UIScrollView 中的内容不会滚动。
public class ScrollingCodeSampleViewController : ViewController
{
private readonly UIFont BODY_FONT = UIFont.FromName("HelveticaNeue", 14f);
private UIScrollView _scrollView;
private UILabel _label;
public ScrollingCodeSampleViewController () : base()
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
BuildView ();
}
public override void ViewDidAppear (bool animated)
{
base.ViewWillAppear (animated);
_scrollView.ContentSize = new CoreGraphics.CGSize (View.Bounds.Width, (_label.Frame.Y + _label.Frame.Height));
}
private void BuildView(){
_scrollView = new UIScrollView (){ TranslatesAutoresizingMaskIntoConstraints = false, ScrollEnabled = true };
View.Add (_scrollView);
_label = new UILabel(){TranslatesAutoresizingMaskIntoConstraints = false, Font = BODY_FONT, TextColor = UIColor.White, Lines = 0, Text = "A lot of text here"};
_label.SizeToFit ();
_scrollView.Add (_label);
View.AddConstraints (new [] {
NSLayoutConstraint.Create(_scrollView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, View, NSLayoutAttribute.Top, 1, 55),
NSLayoutConstraint.Create(_scrollView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, View, NSLayoutAttribute.Left, 1, 0),
NSLayoutConstraint.Create(_scrollView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, View, NSLayoutAttribute.Right, 1, 0),
NSLayoutConstraint.Create(_scrollView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1, -50),
NSLayoutConstraint.Create(_label, NSLayoutAttribute.Top, NSLayoutRelation.Equal, _scrollView, NSLayoutAttribute.Top, 1, 0),
NSLayoutConstraint.Create(_label, NSLayoutAttribute.Left, NSLayoutRelation.Equal, View, NSLayoutAttribute.Left, 1, 15),
NSLayoutConstraint.Create(_label, NSLayoutAttribute.Right, NSLayoutRelation.Equal, View, NSLayoutAttribute.Right, 1, -15)
});
}
}
在 8.4 和 7.1 中调试时,_label.Frame 是 {15, 0, 290, 793}
这足以导致 scrollview 滚动。但是,在 7.1 中,它不滚动。我觉得我缺少一些简单的东西;但是,我找不到它。
虽然 ViewDidAppear(bool) 在 iOS 8.4 和 iOS 9 上工作正常,但 ScrollView 没有设置 contentSize 直到我在 [=14= 的 ViewDidLayoutSubviews() 事件期间设置它] 相反。
我正在 Xamarin 中开发一个应用程序,我在其中使用 UIScrollView 控件,该控件在 iOS 8.4 中滚动得很好;但是,当我在 iOS 7.1 中对其进行测试时,UIScrollView 中的内容不会滚动。
public class ScrollingCodeSampleViewController : ViewController
{
private readonly UIFont BODY_FONT = UIFont.FromName("HelveticaNeue", 14f);
private UIScrollView _scrollView;
private UILabel _label;
public ScrollingCodeSampleViewController () : base()
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
BuildView ();
}
public override void ViewDidAppear (bool animated)
{
base.ViewWillAppear (animated);
_scrollView.ContentSize = new CoreGraphics.CGSize (View.Bounds.Width, (_label.Frame.Y + _label.Frame.Height));
}
private void BuildView(){
_scrollView = new UIScrollView (){ TranslatesAutoresizingMaskIntoConstraints = false, ScrollEnabled = true };
View.Add (_scrollView);
_label = new UILabel(){TranslatesAutoresizingMaskIntoConstraints = false, Font = BODY_FONT, TextColor = UIColor.White, Lines = 0, Text = "A lot of text here"};
_label.SizeToFit ();
_scrollView.Add (_label);
View.AddConstraints (new [] {
NSLayoutConstraint.Create(_scrollView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, View, NSLayoutAttribute.Top, 1, 55),
NSLayoutConstraint.Create(_scrollView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, View, NSLayoutAttribute.Left, 1, 0),
NSLayoutConstraint.Create(_scrollView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, View, NSLayoutAttribute.Right, 1, 0),
NSLayoutConstraint.Create(_scrollView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1, -50),
NSLayoutConstraint.Create(_label, NSLayoutAttribute.Top, NSLayoutRelation.Equal, _scrollView, NSLayoutAttribute.Top, 1, 0),
NSLayoutConstraint.Create(_label, NSLayoutAttribute.Left, NSLayoutRelation.Equal, View, NSLayoutAttribute.Left, 1, 15),
NSLayoutConstraint.Create(_label, NSLayoutAttribute.Right, NSLayoutRelation.Equal, View, NSLayoutAttribute.Right, 1, -15)
});
}
}
在 8.4 和 7.1 中调试时,_label.Frame 是 {15, 0, 290, 793}
这足以导致 scrollview 滚动。但是,在 7.1 中,它不滚动。我觉得我缺少一些简单的东西;但是,我找不到它。
虽然 ViewDidAppear(bool) 在 iOS 8.4 和 iOS 9 上工作正常,但 ScrollView 没有设置 contentSize 直到我在 [=14= 的 ViewDidLayoutSubviews() 事件期间设置它] 相反。