Alexander Anikin's blog

My personal blog

Archive for the ‘Monodevelop’ Category

How to implement Scroll To Top functionality for UIWebView in Monotouch

leave a comment »

Someone can say – this is by default! But I have a case when it’s not.

Imagine – we have a UIWebView within content and it’s almost full fills screen size without needs to be scrolled. But content inside scrolling using Javascript (something like iScroll extension). So iOS thinking: “I shouldn’t  scroll anything for this view.”.  I this case you’ll never get scroll to top event. It’s not firing!

But I found a workaround for this issue. All you need to do just:

1.  Create a fullscreen ScrollView with content size much greater than screen size  – let iOS thinks: “I should support scrolling for this huge view”.

2. Put you UIWebView at random number of pixel below the top of the screen.

3. Switch off handling of ScrollToTop for UIWebView.ScrollView. This must be done because if two controls handle ScrollToTop – nothing works.

4. SetContentOffset to this random number of pixes – to make you UIWebView looks like it placed full-screen.

5. Create ScrollViewDelegate to handle firings of ScrollToTop Event.

That’s it!

Here is the sample code:

const int scrollOffset = 100;

var contentSize = new SizeF (320, 3000);

var scrollToPoint = new PointF (0, scrollOffset);

ScrollView = new UIScrollView();

UI = new DesignedFileManager(Settings);

// UI placed 100px (scrollOffset) lower than top of the screen

UI.Frame = new RectangleF(0, scrollOffset, Window.Frame.Width, Window.Frame.Height+scrollOffset);

// this lines must be there because iOS can’t choose who will support scrolling to top

// so UI web view will not handle scroll to top

UI.ScrollView.ScrollEnabled = false;

UI.ScrollView.ScrollsToTop = false;

// set scroll view frame like window frame

ScrollView.Frame = Window.Frame;

// let scrollview handle scrolling to top

ScrollView.ScrollEnabled = true;

ScrollView.ScrollsToTop = true;

// set scroll view content size bigger than window frame to support scrolling

ScrollView.ContentSize = contentSize;

ScrollView.ShowsVerticalScrollIndicator = false;

ScrollView.ShowsHorizontalScrollIndicator = false;

// scroll to 100px lower, so wevview fills full screen

ScrollView.SetContentOffset(scrollToPoint, false);

ScrollView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;

ScrollView.Delegate = new ScrollViewDelegate(UI);

ScrollView.AddSubview(UI);

_mainView.AddSubview(ScrollView);

And delegate:

class ScrollViewDelegate : UIScrollViewDelegate

{

DesignedFileManager UI;

public ScrollViewDelegate(DesignedFileManager ui) : base()

{

UI = ui;

}

public override bool ShouldScrollToTop(UIScrollView scrollView)

{

Trace.WriteLine(“Scroll to Top invoked.”);

UI.ScrollToTop();

return false;

}

}

Written by Alex Anikin

February 15, 2013 at 6:45 am

Posted in iOS, Mac, Monodevelop, Monotouch

Memory Warning Received and PushViewController

leave a comment »

It was really  great investigation about why iOS application goes to black screen and craches sometimes.

Fisrst of all, I saw this: Received memory warning. Level 1

After that it goes to black screen. This is very interesting, application was working fine if no applications was started in background (I imagined – there are no free memory… but strange…). But, as I can see later, this is view was unloaded only. Several articles wrote – if view has no SuperView it will be unloaded when UIViewController receive memory warning. But this was obviously our fault. After huge  changes in UI we decided to use only one UIWebView. But some code was moved to new version, and  PushViewController invoke too. This is not clear for me now what exactly change this method, but it do something and view unloading after memory warning receive.  So we just remove this line and no black screen (means unloaded view) now.

Written by Alex Anikin

August 4, 2012 at 7:53 pm

Posted in C#, iOS, Mac, Monodevelop, Monotouch

TFS Addin for Monodevelop – error adding repository

leave a comment »

Found strange issue when trying to add new repository using TFS Addin in Monodevelop (ver 4.0.3.4) on my Mac.

After I setup repository and click button to add – get this error:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.Xml.XmlException: Document element did not appear. Line 1, position 1. at Mono.Xml2.XmlTextReader.Read () [0x00000] in <filename unknown>:0 at System.Xml.XmlTextReader.Read () [0x00000] in <filename unknown>:0 at System.Xml.XmlReader.MoveToContent () [0x00000] in <filename unknown>:0 at MonoDevelop.Core.Serialization.XmlConfigurationReader.Read (System.Xml.XmlReader reader) [0x0000d] in /Users/builder/data/lanes/monodevelop-mac-monodevelop-3.0.3-branch/43da787a/source/monodevelop/main/src/core/ MonoDevelop.Core/MonoDevelop.Core.Serialization/XmlDataSerializer.cs:238 at MonoDevelop.Core.Serialization.XmlDataSerializer.Deserialize (System.Xml.XmlReader reader, System.Type type) [0x00000] in /Users/builder/data/lanes/monodevelop-mac-monodevelop-3.0.3-branch/43da787a/source/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Serialization/XmlDataSerializer.cs:102 at MonoDevelop.VersionControl.VersionControlService.GetConfiguration () [0x00034] in /Users/builder/data/lanes/monodevelop-mac-monodevelop-3.0.3-branch/43da787a/source/monodevelop/main/src/addins/VersionControl/ MonoDevelop.VersionControl/MonoDevelop.VersionControl/VersionControlService.cs:597 at MonoDevelop.VersionControl.VersionControlService.AddRepository (MonoDevelop.VersionControl.Repository repo) [0x00000] in /Users/builder/data/lanes/monodevelop-mac-monodevelop-3.0.3-branch/43da787a/source/monodevelop/main/src/addins/VersionControl/ MonoDevelop.VersionControl/MonoDevelop.VersionControl/VersionControlService.cs:577 at TeamAddins.VersionControl.TFS.GUI.RepositoryMenu.AddRepositoryHandler (System.Object sender, System.EventArgs e) [0x00000] in <filename unknown>:0 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 — End of inner exception stack trace — at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0 at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0 at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0 at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <filename unknown>:0 at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x00000] in <filename unknown>:0 at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x00000] in <filename unknown>:0 at GLib.SignalClosure.MarshalCallback (IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) [0x00000] in <filename unknown>:0

 

Solution is easy – you should open the directory: /Users/<Your Login>/Library/Preferences/MonoDevelop-3.0 and look into the file ‘VersionControl.config’. In my case it was empty. This means – corrupted. Just delete it and Monodevelop will recreate it. This will be fixed as bug in future releases.

Written by Alex Anikin

July 26, 2012 at 10:31 pm

Posted in Mac, Monodevelop