我正在尝试实现类似Snapchat的功能,其中用户通过向左或向右滑动来浏览视图。我正在使用UIPageViewController。
当我滑到UIImagePickerController视图时出现问题。当用户滑动到该视图上时,相机会正确显示,但是当用户放开屏幕并且视图锁定到位时,相机几乎完全模糊,就像对其施加雾层一样,然后重新聚焦回正常。 / p>
奇怪的是,如果过渡样式是“Page Curl”,则不会发生这种情况。它只发生在“滚动”上。
如何阻止此行为?
4在故事板中查看控制器 - Master,PageView,Home和Create(主代码和创建代码)
感谢。
HeroMasterViewController类:
partial class HeroMasterViewController : ViewControllerBase IUIPageViewControllerDataSource
{
private UIViewController[] _heroViewControllers;
private UIPageViewController _heroPageViewController;
public HeroMasterViewController (IntPtr handle) : base (handle, Navigation.Page.HeroMaster)
{
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
_heroPageViewController = this.Storyboard.InstantiateViewController ("HeroPageViewController") as UIPageViewController;
_heroPageViewController.DataSource = this;
InitViewControllers ();
var startingViewController = new UIViewController[1] { _heroViewControllers [0] };
_heroPageViewController.SetViewControllers (startingViewController, UIPageViewControllerNavigationDirection.Forward, true, null);
_heroPageViewController.View.Frame = new CoreGraphics.CGRect (0, 0, this.View.Frame.Width, this.View.Frame.Size.Height);
this.AddChildViewController (_heroPageViewController);
this.View.AddSubview(_heroPageViewController.View);
_heroPageViewController.DidMoveToParentViewController(this);
}
public void InitViewControllers()
{
_heroViewControllers = new UIViewController[2];
_heroViewControllers [0] = this.Storyboard.InstantiateViewController ("HomeViewController");
_heroViewControllers [1] = this.Storyboard.InstantiateViewController ("CreateViewController");
}
public UIViewController GetPreviousViewController (UIPageViewController pageViewController, UIViewController referenceViewController)
{
var controller = referenceViewController as HeroViewControllerBase;
if (controller.Index == 0)
return null;
return _heroViewControllers[controller.Index - 1];
}
public UIViewController GetNextViewController (UIPageViewController pageViewController, UIViewController referenceViewController)
{
var controller = referenceViewController as HeroViewControllerBase;
if (controller.Index == (_heroViewControllers.Length - 1))
return null;
return _heroViewControllers[controller.Index + 1];
}
}
CreateViewController类:
partial class CreateViewController : HeroViewControllerBase
{
private Xamarin.Media.MediaPicker Picker;
private MediaPickerController MediaController;
public CreateViewController (IntPtr handle) : base (handle, Navigation.Page.HeroCreate, 1)
{
this.Picker = new Xamarin.Media.MediaPicker();
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
DisplayPicker ();
}
private void DisplayPicker()
{
if (this.MediaController != null)
return;
this.MediaController = this.Picker.GetTakePhotoUI(new StoreCameraMediaOptions
{
Name = DateTime.Now.ToFileTimeUtc() + ".jpg",
Directory = "MediaPickerSample"
});
this.MediaController.AllowsEditing = false;
this.MediaController.ShowsCameraControls = false;
this.MediaController.AllowsImageEditing = false;
this.MediaController.CameraDevice = UIImagePickerControllerCameraDevice.Front;
this.MediaController.View.Frame = new CGRect (0, 0, this.View.Frame.Width, this.View.Frame.Height);
var translate = CGAffineTransform.MakeTranslation (0, 71.0f);
this.View.AddSubview(this.MediaController.View);
}
}