MVVMCross iOS:切换到不同的视图模型时如何将命令与自定义转换绑定 [英] MVVMCross iOS: how to bind a command with Custom transition when switching to different View model
问题描述
对于 MVVMCross ios,如何使用不同的 TransitionalStyle,例如 FlipHorizontal 样式,而不是ShowViewModel"的默认滑动效果?
For MVVMCross ios, how can I use different TransitionalStyle such as FlipHorizontal style instead of the default sliding effect with "ShowViewModel"?
[Register("SearchResults")]
public class SearchResultsView : MvxTableViewController
{
public override void ViewDidLoad()
{
Title = "List";
base.ViewDidLoad();
var mapButton = new UIButton(new RectangleF(0, 0, 65, 30));
mapButton.SetBackgroundImage(UIImage.FromBundle("images/map_btn.png"), UIControlState.Normal);
mapButton.TouchUpInside += MapButtonClicked();
var rightButton = new UIBarButtonItem(mapButton);
NavigationItem.RightBarButtonItem = rightButton;
var bindings = this.CreateBindingSet<SearchResultsView, SearchResultsViewModel>();
//bindings.Bind(mapButton).To(x => x.ShowMapCommand); //how to do with binding command?
bindings.Apply();
}
private EventHandler MapButtonClicked()
{
return (sender, args) =>
{
var mapView = new SearchResultMapView {ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal};
var navigationController = new UINavigationController(mapView);
PresentViewController(navigationController, true, null);
};
}
}
推荐答案
ViewModels/Views 使用 Presenter 呈现.
ViewModels/Views are presented using a Presenter.
对于导航控制器的模态显示,有些人使用 MvxModalNavSupportTouchViewPresenter.cs
For Modal displays of navigation controllers, some people use the MvxModalNavSupportTouchViewPresenter.cs
您可以通过在设置中覆盖 CreatePresenter
来使用此演示者:
You can use this presenter by overriding CreatePresenter
in Setup:
protected override IMvxTouchViewPresenter CreatePresenter()
{
return new MvxModalNavSupportTouchViewPresenter(ApplicationDelegate, Window);
}
完成此操作后,您应该能够通过添加 IMvxModalTouchView
继承并在 的构造函数中设置
.ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal;
来实现过渡效果>SearchResultMapView
With this done then you should be able to achieve your transition effect by adding IMvxModalTouchView
inheritance and by setting ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal;
in the constructor for your SearchResultMapView
.
public class SearchResultMapView
: MvxViewController, IMvxModalTouchView
{
public SearchResultMapView()
{
ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal;
}
// more code here....
}
或者,如果您想完全自定义视图/视图控制器的呈现,那么实现自定义呈现器是相当简单的 - 有关更多信息,请参阅 http://slodge.blogspot.co.uk/2013/06/presenter-roundup.html
Alternatively, if you wanted to completely customise the presentation of the view/viewcontroller, then implementing a custom presenter is fairly straight-forward to do - for more information, see some of the articles and tutorials on custom presenters in http://slodge.blogspot.co.uk/2013/06/presenter-roundup.html
这篇关于MVVMCross iOS:切换到不同的视图模型时如何将命令与自定义转换绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!