【发布时间】:2015-09-28 18:06:59
【问题描述】:
我正在 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},这足以导致滚动视图滚动。但是,在 7.1 中,它不是滚动的。我觉得我错过了一些简单的东西;但是,我找不到它。
【问题讨论】:
标签: ios uiscrollview xamarin