为什么ContentView Width在iOS(Xamarin)中自动改变和水平滚动
Why ContentView Width automatically change and scroll Horizontal in iOS(Xamarin)
我是 iOS 和 Xamarin 的新手。我创建了 ScrollView
,它在 Horizontal
和 Vertical
上滚动。但我只想要 Vertical
滚动。让我简单解释一下。
这是我的视图层次结构:
View
-> ScrollView
-> ContainerView
-> UILabel
我正在制作通用应用程序所以我选择 Generic
设备。 width = 600
和 Height = 600
.
我的ScrollView约束我是这样设置的
Top Space to SuperView : 0
Trailing Space to SuperView : 0
Leading Space to SuperView : 0
Bottom Space to SuperView : 0
和 ContentView 约束低于
Top Space to ScrollView : 0
Trailing Space to ScrollView : 0
Leading Space to ScrollView : 0
Bottom Space to SuperView : 30
而且我还在 ViewDidLayoutSubViews
方法中设置了 Frame
。
public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews();
scrollView.ContentSize = addressContentView.Frame.Size;
scrollView.LayoutIfNeeded();
}
在设置 Upper 为什么我的 ScrollView
正在使用 Horizontal
滚动之后。因为我设置 ContentView
宽度等于 ScrollView
.
任何帮助不胜感激。如果您需要比我更详细的信息。
花了 1 小时后,我终于得到了解决方案,我将约束更改为以下,并且它仅适用于我想要的 Vertical
滚动。
滚动视图约束:
Top Space to SuperView : 0
Trailing Space to SuperView : 0
Leading Space to SuperView : 0
Bottom Space to SuperView : 0
和ContentView 约束:
Top space to ScrollView : 0
Leading space to ScrollView : 0
Trailing space to Scrollview : 0
Width = scrollView.width = contentView.width
我是 iOS 和 Xamarin 的新手。我创建了 ScrollView
,它在 Horizontal
和 Vertical
上滚动。但我只想要 Vertical
滚动。让我简单解释一下。
这是我的视图层次结构:
View
-> ScrollView
-> ContainerView
-> UILabel
我正在制作通用应用程序所以我选择 Generic
设备。 width = 600
和 Height = 600
.
我的ScrollView约束我是这样设置的
Top Space to SuperView : 0
Trailing Space to SuperView : 0
Leading Space to SuperView : 0
Bottom Space to SuperView : 0
和 ContentView 约束低于
Top Space to ScrollView : 0
Trailing Space to ScrollView : 0
Leading Space to ScrollView : 0
Bottom Space to SuperView : 30
而且我还在 ViewDidLayoutSubViews
方法中设置了 Frame
。
public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews();
scrollView.ContentSize = addressContentView.Frame.Size;
scrollView.LayoutIfNeeded();
}
在设置 Upper 为什么我的 ScrollView
正在使用 Horizontal
滚动之后。因为我设置 ContentView
宽度等于 ScrollView
.
任何帮助不胜感激。如果您需要比我更详细的信息。
花了 1 小时后,我终于得到了解决方案,我将约束更改为以下,并且它仅适用于我想要的 Vertical
滚动。
滚动视图约束:
Top Space to SuperView : 0
Trailing Space to SuperView : 0
Leading Space to SuperView : 0
Bottom Space to SuperView : 0
和ContentView 约束:
Top space to ScrollView : 0
Leading space to ScrollView : 0
Trailing space to Scrollview : 0
Width = scrollView.width = contentView.width