For some odd reason is my UIImagePickerController not showing up running this code ? Can you see the problem ?
this is on my Iphone 5 - I only get a black screen appearing - and I cannot do any interaction
var pictureViewer = new PictureViewController((APTask)GetItem(e.IndexPath.Row), e.IndexPath);
parent.NavigationController.PresentViewController(pictureViewer, true, null);
This is picture classview class:
public class PictureViewController : UIViewController, IUINavigationControllerDelegate
{
private UIImagePickerController _imagePicker;
private APTask _task;
private NSIndexPath _indexPath;
private UIImage _image;
private NSDictionary _imageMetadata;
public PictureViewController(APTask task, NSIndexPath indexPath)
{
this._task = task;
this._indexPath = indexPath;
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
_imagePicker = new UIImagePickerController ();
// set our source to the photo library
_imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
_imagePicker.ModalPresentationStyle = UIModalPresentationStyle.CurrentContext;
// set what media types
// _imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes (UIImagePickerControllerSourceType.PhotoLibrary);
_imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia;
_imagePicker.Canceled += Handle_Canceled;
_imagePicker.Delegate = this;
PresentViewController(_imagePicker, true, null);
}
You would need to present the UIImagePickerController at the competition of presenting your pictureViewer as it is a UIViewController
Your code:
parent.NavigationController.PresentViewController(pictureViewer, true, null);
Would need to not pass null for the competition handler. You could expose a pubic method on your PictureViewController class that does the creation/presentation of the UIImagePickerController and pass that Action (method) as the handler...
But why create/present an empty UIViewController just to than cover it up with a UIImagePickerController, here is how I do it...
Note: This code also handles iPad presentation properly and if you are requesting the camera within the Simulator it defaults to the PhotoLibrary to avoid the native ObjC exception.
public partial class myViewController : UIViewController
{
UIImagePickerController _imagePickerController;
public myViewController (IntPtr handle) : base (handle) { }
partial void myButtonTouch(UIButton sender)
{
ImagePickerController(UIImagePickerControllerSourceType.Camera);
}
public void ImagePickerController(UIImagePickerControllerSourceType sourceType)
{
if (_imagePickerController == null)
_imagePickerController = new UIImagePickerController();
if (Runtime.Arch == Arch.DEVICE) // No camara on Simulator
_imagePickerController.SourceType = sourceType;
else
if (sourceType == UIImagePickerControllerSourceType.Camera)
_imagePickerController.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) // Handle ipad correctly
{
if (_imagePickerController.SourceType == UIImagePickerControllerSourceType.Camera)
_imagePickerController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
else
_imagePickerController.ModalPresentationStyle = UIModalPresentationStyle.Popover;
}
else
{
_imagePickerController.ModalPresentationStyle = UIModalPresentationStyle.CurrentContext;
}
_imagePickerController.Canceled += (object sender, EventArgs e) =>
{
Console.WriteLine("Picker Cancelled");
_imagePickerController.DismissViewController(true, null);
};
_imagePickerController.FinishedPickingMedia += (object sender, UIImagePickerMediaPickedEventArgs e) =>
{
_imagePickerController.DismissViewController(true, null);
Console.WriteLine(e.ReferenceUrl);
if (_imagePickerController.SourceType == UIImagePickerControllerSourceType.Camera)
{
// Newly-captured media, save it to the Camera Roll on the device or ....
}
else
{
// Existing media seleted, do something with it....
}
};
var mainWindow = UIApplication.SharedApplication.KeyWindow;
var viewController = mainWindow?.RootViewController;
while (viewController?.PresentedViewController != null)
{
viewController = viewController.PresentedViewController;
}
if (viewController == null)
viewController = this;
_imagePickerController.View.Frame = viewController.View.Frame;
viewController.PresentViewController(_imagePickerController, true, () => { Console.WriteLine("Complete"); });
}
}
Note: You can extract out the ImagePickerController method and add it to as static method somewhere to reuse as while (viewController?.PresentedViewController != null) code section will always find the correct context in which to present the modal controller.
Related
I want make an apps that play audio and video. I want the audio can play on background mode, so I add the MediaPlayerInfo. While I do not want the video played on background mode. So I do not need the MediaPlayerInfo while play video.
But somehow the MediaPlayerInfo still shown in notification bar while I play the video, although I didn't set it.
I already try to set is as "null" but it didn't change the behavior.
Anyone can help me to make the MediaPlayerInfo shown while play audio in background mode, but did not shown while play video (background & foreground mode)?
(Update) this is snippet of my code:
private MPRemoteCommandCenter m_commandCenter = MPRemoteCommandCenter.Shared;
private string m_currentAudioTitle = "";
private MPNowPlayingInfo _currentFileInfo;
NSObject _playCommandTarget;
NSObject _pauseCommandTarget;
NSObject _skipBackwardCommandTarget;
NSObject _skipForwardCommandTarget;
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
m_observerList.Add(NSNotificationCenter.DefaultCenter.AddObserver(aName: UIApplication.DidEnterBackgroundNotification, notify: HandleDidEnterBackgroundNotification));
m_observerList.Add(NSNotificationCenter.DefaultCenter.AddObserver(aName: UIApplication.WillEnterForegroundNotification, notify: HandleWillEnterForegroundNotification));
}
public override void ViewWillDisappear(bool animated)
{
base.ViewWillDisappear(animated);
foreach (NSObject _observer in m_observerList)
{
NSNotificationCenter.DefaultCenter.RemoveObserver(_observer);
}
}
private void HandleWillEnterForegroundNotification(NSNotification obj)
{
RemoveRemoteTransportControl();
RemoveNowPlaying();
}
private void HandleDidEnterBackgroundNotification(NSNotification obj)
{
SetupRemoteTransportControl();
SetupNowPlaying("Test Asset Name");
}
public void SetupRemoteTransportControl()
{
m_commandCenter.SkipBackwardCommand.Enabled = true;
m_commandCenter.SkipForwardCommand.Enabled = true;
_playCommandTarget = m_commandCenter.PlayCommand.AddTarget(PlayAudioBackground);
_pauseCommandTarget = m_commandCenter.PauseCommand.AddTarget(PauseAudioBackground);
_skipBackwardCommandTarget = m_commandCenter.SkipBackwardCommand.AddTarget(SkipBackwardBackground);
_skipForwardCommandTarget = m_commandCenter.SkipForwardCommand.AddTarget(SkipForwardBackground);
}
public void RemoveRemoteTransportControl()
{
m_commandCenter.SkipBackwardCommand.Enabled = false;
m_commandCenter.SkipForwardCommand.Enabled = false;
m_commandCenter.PlayCommand.RemoveTarget(_playCommandTarget);
m_commandCenter.PauseCommand.RemoveTarget(_pauseCommandTarget);
m_commandCenter.SkipBackwardCommand.RemoveTarget(_skipBackwardCommandTarget);
m_commandCenter.SkipForwardCommand.RemoveTarget(_skipForwardCommandTarget);
m_commandCenter.Dispose();
}
public void SetupNowPlaying(string aAssetTitle = null)
{
_currentFileInfo = new MPNowPlayingInfo();
if (!string.IsNullOrEmpty(aAssetTitle))
{
m_currentAudioTitle = aAssetTitle;
}
Console.WriteLine("SetupNowPlaying: "+ m_currentAudioTitle);
_currentFileInfo.Title = m_currentAudioTitle;
_currentFileInfo.ElapsedPlaybackTime = apPlayer.CurrentTime.Seconds;
_currentFileInfo.PlaybackDuration = m_audioAsset.Duration.Seconds;
MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = _currentFileInfo;
}
public void RemoveNowPlaying()
{
MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = _currentFileInfo;
}
I'm using a Xamarin.Forms grid application to show a couple of html elements as WebViews in the cells of the grid CardGrid:
private async void CreateCardView()
{
CardGrid.Children.Clear();
// idx over all count elements of html snippets
for (idx = 0; idx < count; idx++)
{
string html = AuthoringCard(idx);
RenderingCard(html, idx);
}
}
AuthoringCard() creates the html code snippet.
RenderingCard() creates the WebView inside the grid cell.
private void RenderingCard(string htmlCard, int index)
{
int CardWidth = 300;
int CardHeight = 150;
int CardNoHorizontally = 3;
WebView uiCard = new WebView();
uiCard.HeightRequest = CardHeight - 5;
uiCard.WidthRequest= CardWidth - 5;
uiCard.VerticalOptions = LayoutOptions.Start;
uiCard.HorizontalOptions = LayoutOptions.Center;
uiCard.Margin = new Thickness(0);
uiCard.AutomationId = index.ToString();
uiCard.Focused += Card_Tapped;
uiCard.InputTransparent = false;
var htmlSource1 = new HtmlWebViewSource
{
Html = htmlCard,
};
uiCard.Source = htmlSource1;
CardGrid.Children.Add(uiCard);
int row = (int)Math.Floor((double)(index / CardNoHorizontally));
int column = index - (row * CardNoHorizontally);
Grid.SetRow(uiCard, row);
Grid.SetColumn(uiCard, column);
}
I want to catch the Focused event, when the user it tapping on the card (WebView) and using the AutomationId to get the index of the card (html code snippet):
private void Card_Tapped(object sender, EventArgs e)
{
WebView card = (WebView)sender;
int index = Convert.ToInt16(card.AutomationId));
}
This works fine with Android. Under iOS the event is never raised. Any idea for a solution?
Cause:
the property Focus in Forms correspond method that we called becomeFirstResponder in native iOS platform.Unfortunately,UIWebView and WKwebview do not support the method becomeFirstResponder.This method is only available in some 'input-controls' Such as UITextField and UITextView(Entry in Forms).So even if you set the event on a webview.It will not work in iOS.
Workaround:
You can add a TapGestureRecognizer on the webview.And you have to implement it by using CustomRenderer.Because it will create conflict if you add TapGestureRecognizer in forms.
Refer to the following code.
in Forms
public MainPage()
{
if (Device.RuntimePlatform == "iOS")
{
MessagingCenter.Subscribe<Object,string>(this,"webview_click", (sender,arg)=> {
// int index = Convert.ToInt16(arg));
});
}
}
in iOS
using System;
using Foundation;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using xxx;
using xxx.iOS;
using ObjCRuntime;
[assembly:ExportRenderer(typeof(WebView),typeof(MyWebViewRenderer))]
namespace xxx.iOS
{
public class MyWebViewRenderer : WebViewRenderer, IUIGestureRecognizerDelegate
{
public bool isFirstLoad = true;
public MyWebViewRenderer()
{
}
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e != null)
{
UITapGestureRecognizer tap = new UITapGestureRecognizer(this, new Selector("Tap_Handle:"));
tap.WeakDelegate = this;
this.AddGestureRecognizer(tap);
}
}
[Export("gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:")]
public bool ShouldRecognizeSimultaneously(UIGestureRecognizer gestureRecognizer, UIGestureRecognizer otherGestureRecognizer)
{
return true;
}
[Export("Tap_Handle:")]
void Tap_Handle(UITapGestureRecognizer tap)
{
if(isFirstLoad)
{
isFirstLoad = false;
MessagingCenter.Send<Object,string>(this, "webview_click",Element.AutomationId);
}
}
}
}
I would like to know the scroll position of ViewCell inside the ListView.
Tried with various ways but always that gives me 0 value.
My intension is to get ViewCell's position in screen. In order to resolve this problem trying to get it's scroll position and then i will add this value to the Y value of ListView object.
Can anybody please help me in this case?
you have to make custom renderer of the ViewCell its kinda tricky to send the positions to pcl then we subscribe to the event in the view here's my code
PCL
public class SAChatViewCell : ViewCell
{
public delegate int[] IntEventHandler(object sender, float[] postion);
public event IntEventHandler OnCellItemLongClicked;
public event EventHandler OnCellItemTouched;
public void InvokeOnCellItemLongClicked(object sender, float[] e)
{
//send the current grid
OnCellItemLongClicked?.Invoke(sender, e);
}
public void InvokeOnCellItemTouched(object sender, EventArgs e)
{
//send the current grid
OnCellItemTouched?.Invoke(sender, e);
}
}
Android Renderer
class SAChatViewCellRenderer : ViewCellRenderer
{
private bool selected;
ClickListener handler = new ClickListener();
static Android.Widget.ListView listView;
Xamarin.Forms.ListView listviewforms;
static SAChatViewCell cellElement;
Android.Views.View cellControl;
protected override Android.Views.View GetCellCore(Cell item, Android.Views.View convertView, Android.Views.ViewGroup parent, Android.Content.Context context)
{
try
{
if (cellControl == null)
{
cellControl = base.GetCellCore(item, convertView, parent, context);
}
cellElement = item as SAChatViewCell;
selected = false;
listviewforms = cellElement.View.Parent.Parent as Xamarin.Forms.ListView;
if (listviewforms == null)
{
return null;
}
if (listviewforms.BackgroundColor.ToAndroid() == Color.Transparent.ToAndroid())
{
cellControl.SetBackgroundColor(Color.White.ToAndroid());
}
else
{
cellControl.SetBackgroundColor(listviewforms.BackgroundColor.ToAndroid());
}
cellControl.SetOnLongClickListener(handler);
cellControl.SetOnTouchListener(handler);
return cellControl;
}
catch (Exception ex)
{
return null;
}
}
protected override void OnCellPropertyChanged(object sender, PropertyChangedEventArgs args)
{
base.OnCellPropertyChanged(sender, args);
if (args.PropertyName == "IsSelected")
{
// I had to create a property to track the selection because cellCore.Selected is always false.
// Toggle selection
selected = !selected;
var selectedBackground = cellElement.SelectedBackgroundColor.ToAndroid();
if (selected)
{
if (selectedBackground == Color.Transparent.ToAndroid())
{
cellControl.SetBackgroundColor(Color.White.ToAndroid());
return;
}
cellControl.SetBackgroundColor(selectedBackground);
}
else
{
if (listviewforms.BackgroundColor.ToAndroid() == Color.Transparent.ToAndroid())
{
cellControl.SetBackgroundColor(Color.White.ToAndroid());
}
else
{
cellControl.SetBackgroundColor(listviewforms.BackgroundColor.ToAndroid());
}
}
}
}
internal class ClickListener : Java.Lang.Object, IOnLongClickListener, IOnTouchListener
{
//event priority Touch - LongClick - Click
//NOTE: return true to indicate that we have handled the event and it should stop here;
public bool OnLongClick(Android.Views.View sender)
{
var cellItem = sender as INativeElementView;
var viewCell = sender as Android.Views.View;
float[] location = new float[] { 0, 0 };
Android.Views.View parentRow = (Android.Views.View)viewCell.Parent;
listView = (Android.Widget.ListView)parentRow.Parent;
int position = listView.GetPositionForView(parentRow);
var x = parentRow.Right;
var y = (parentRow.Top - listView.DividerHeight) <= 0 ? parentRow.Bottom : parentRow.Top;
int view_height = parentRow.Height;
location[0] = (x / MainActivity.Current.Resources.DisplayMetrics.Density);
location[1] = y / MainActivity.Current.Resources.DisplayMetrics.Density;
//send current cell
cellElement.InvokeOnCellItemLongClicked((cellItem.Element as ViewCell).View, location);
listView.Scroll += ListView_Scroll;
return true;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (listView != null)
{
listView.Scroll -= ListView_Scroll;
}
}
private void ListView_Scroll(object sender, Android.Widget.AbsListView.ScrollEventArgs e)
{
cellElement.InvokeOnCellItemTouched(cellElement.View, EventArgs.Empty);
}
//return false if you have not handled it and/or the event should continue to any other on-click listeners.
public bool OnTouch(Android.Views.View v, MotionEvent e)
{
if (e.Action == MotionEventActions.Down)
{
cellElement.InvokeOnCellItemTouched(cellElement.View, EventArgs.Empty);
//cellCore.SetOnTouchListener(this);
}
return false;
}
}
}
}
iOS Renderer
class SAUITableViewCell : UITableViewCell
{
public override void TouchesBegan(NSSet touches, UIEvent evt)
{
base.TouchesBegan(touches, evt);
}
}
//When you scroll, your cells are created in real time. cells aren't created from scratch, instead iOS just takes a cell that has just left the screen and sends it through
class SAChatViewCellRenderer : ViewCellRenderer, IUIGestureRecognizerDelegate
{
UITableView TV;
SAChatViewCell cellElement;
public IntPtr Handle => new IntPtr();
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
{
try
{
UITableViewCell cell = base.GetCell(item, reusableCell, tv);
TV = tv;
var uiTapGestureRecognize = new UITapGestureRecognizer(OnClick);
var uiLongPressGestureRecognizer = new UILongPressGestureRecognizer(OnLongClick);
uiLongPressGestureRecognizer.MinimumPressDuration = 0.5;
cell.AddGestureRecognizer(uiTapGestureRecognize);
cell.AddGestureRecognizer(uiLongPressGestureRecognizer);
cellElement = item as SAChatViewCell;
cell.BackgroundColor = UIColor.Clear;
if (cellElement.SelectedBackgroundColor == Color.Transparent)
{
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
}
else
{
cell.SelectedBackgroundView = new UIView
{
BackgroundColor = cellElement.SelectedBackgroundColor.ToUIColor() ?? default(UIColor)
};
}
return cell;
}
catch (Exception ex)
{
throw ex;
}
}
private void OnLongClick(UILongPressGestureRecognizer arg)
{
//get the current touch coords based on listview
CGPoint coords = arg.LocationInView(TV);
//current cell
if (arg.State != UIGestureRecognizerState.Began)
{
var indexPath = TV.IndexPathForRowAtPoint(coords);
CGRect Rect = TV.RectForRowAtIndexPath(indexPath);
//delete the listview offset
Rect.Offset(-TV.ContentOffset.X, -TV.ContentOffset.Y);
var CurrentViewCell = (arg.View as UIKit.UITableViewCell).Superview;
//Note : xamarin forms cell element MonoTouch creates it's own internal delegate type for UIScrollView so we either override the uiviewtable or trigger the ondisappear event
var cellItem = arg.View as INativeElementView;
(((cellItem.Element as ViewCell).Parent) as ListView).ItemDisappearing += (s, o) =>
{
cellElement.InvokeOnCellItemTouched(cellElement.View, EventArgs.Empty);
};
float[] location = new float[] { 0, 0 };
location[0] = (float)Rect.X;
var Y = Rect.Top <= 0 ? Rect.Bottom : Rect.Top;
location[1] = (float)Y;
cellElement.InvokeOnCellItemLongClicked((cellItem.Element as ViewCell).View, location);
}
}
private void OnClick()
{
cellElement.InvokeOnCellItemTouched(cellElement.View, EventArgs.Empty);
}
public void Dispose()
{
throw new NotImplementedException();
}
}
}
I have found a solution,
Problem :
My intension is to get ViewCell's position in screen
Solution :
Step 1 : Keep scrollview inside the Relative layout.
Step 2 : When user click on scroll view's ViewCell, save touch point (X, Y) of relative layout. In Y co-ordinate, add top position of relative layout so you will get touch point relative to whole screen.
Step 3 : When user click on scroll view's ViewCell, call XYZ() method.
Step 4 : Inside XYZ() method, do whatever functionality which required on (X, Y) co-ordinate. (Note : put 300ms delay in doing functionality in XYZ() method, as step-2 required some time in saving
touch points.)
I need a label with large text like a article which needs pinch to zoom capability for that I have written a ZoomableScrollview which works fine in IOS and Windows but not in android. Please see the code below.
Code in PCL
public class ZoomableScrollView:ScrollView
{
public static readonly BindableProperty MinimumZoomScaleProperty = BindableProperty.Create("MinimumZoomScale", typeof(float), typeof(ZoomableScrollView), default(float));
public float MinimumZoomScale
{
get { return (float)GetValue(MinimumZoomScaleProperty); }
set { SetValue(MinimumZoomScaleProperty, value); }
}
public static readonly BindableProperty MaximumZoomScaleProperty = BindableProperty.Create("MaximumZoomScale", typeof(float), typeof(ZoomableScrollView), default(float));
public float MaximumZoomScale
{
get { return (float)GetValue(MaximumZoomScaleProperty); }
set { SetValue(MaximumZoomScaleProperty, value); }
}
}
IOS renderer
public class ZoomableScrollViewRenderer : ScrollViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.NewElement == null)
return;
if (e.OldElement == null)
{
ZoomableScrollView zsv = Element as ZoomableScrollView;
this.MinimumZoomScale = zsv.MinimumZoomScale;
this.MaximumZoomScale = zsv.MaximumZoomScale;
this.ViewForZoomingInScrollView += (UIScrollView sv) => { return this.Subviews[0]; };
}
}
}
Windows renderer
public class ZoomableScrollViewRenderer:ScrollViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<ScrollView> e)
{
base.OnElementChanged(e);
if (e.NewElement == null)
return;
if (e.OldElement == null)
{
ZoomableScrollView zsv = Element as ZoomableScrollView;
this.Control.ZoomMode = Windows.UI.Xaml.Controls.ZoomMode.Enabled;
this.Control.MinZoomFactor = zsv.MinimumZoomScale;
this.Control.MaxZoomFactor = zsv.MaximumZoomScale;
}
}
}
Android renderer
public class ZoomableScrollViewRenderer:ScrollViewRenderer
{
float originalDistanceX, currentdistanceX, originalDistanceY, currentdistanceY;
bool IsPinching = false;
double currentScale;
TeluguLabel lbl;
ScrollView svMain, svSub;
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
svMain = ((ScrollView)e.NewElement);
lbl = svMain.Content as TeluguLabel;
svSub = new ScrollView();
svSub.Orientation = ScrollOrientation.Horizontal;
svSub.Content = lbl;
svMain.Content = svSub;
lbl.AnchorX = 0;
lbl.AnchorY = 0;
}
public override bool OnTouchEvent(MotionEvent e)
{
if (e.PointerCount > 1)
{
IsPinching = true;
currentScale = lbl.Scale;
originalDistanceX = Math.Abs(e.GetX(0) - e.GetX(1));
originalDistanceY = Math.Abs(e.GetY(0) - e.GetY(1));
}
else
{
IsPinching = false;
}
return base.OnTouchEvent(e);
}
public override bool DispatchTouchEvent(Android.Views.MotionEvent e)
{
switch (e.Action)
{
case MotionEventActions.Down:
this.Parent.RequestDisallowInterceptTouchEvent(true);
break;
case MotionEventActions.Move:
if(IsPinching && e.PointerCount > 1)
{
currentdistanceX = Math.Abs(e.GetX(0) - e.GetX(1));
currentdistanceY = Math.Abs(e.GetY(0) - e.GetY(1));
if (originalDistanceX < currentdistanceX || originalDistanceY < currentdistanceY)
lbl.Scale = currentScale + 0.01;
else if (originalDistanceX > currentdistanceX || originalDistanceY > currentdistanceY)
lbl.Scale = currentScale - 0.01;
}
break;
case MotionEventActions.Up:
this.Parent.RequestDisallowInterceptTouchEvent(false);
break;
}
return base.DispatchTouchEvent(e);
}
}
in android I was able to achieve zoom to some extent but the scrolling in not smooth, but I compromised for it. Now the problem is the text is getting stripped in the label. Somebody please help me my app itself is for reading which is he basic feature not working.
Thanks in advance
I got it. Basically android label has no of lines limit of 100, i have to override it in the renderer
label.SetMaxLines(4000);
I'm trying to implement a Snapchat like feature where the views are navigated by the user swiping left or right. I'm using a UIPageViewController for this.
There is a problem though when I slide onto a UIImagePickerController view. The camera displays properly as the user is sliding onto that view, however when the user lets go of the screen and the view locks into place the camera fully blurs almost as if a fog layer is applied to it and then refocuses back to normal.
The weird thing is this doesn't occur if the transition style is "Page Curl". It only happens on "Scroll".
How can I stop this behaviour?
4 View Controllers in storyboard - Master, PageView, Home and Create (code for master and create below)
Thanks.
HeroMasterViewController class:
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 class:
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);
}
}