Changing StatusBar orientation has no effect - xamarin.ios

I have two ViewControllers - the main one is Portrait only - the second, which displays a WebView loaded with a YouTube video can rotate to any orientation. When it is dismissed in Landscape, returning to the main ViewController, the status bar is left in Landscape mode. I know when the YouTube view is dismissed and have placed the following line on code in the called method:
UIApplication.SharedApplication.SetStatusBarOrientation(UIInterfaceOrientation.Portrait,true);
But it has no effect on the status bar. Is there some other place to set the orientation? Other ideas?
Thanks,
Rick

Fixed the problem by adding the following to the AppDelegate
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations (UIApplication application, UIWindow forWindow)
{
return UIInterfaceOrientationMask.AllButUpsideDown;
}
Then this code actually did what it is supposed to:
UIApplication.SharedApplication.SetStatusBarOrientation(UIInterfaceOrientation.Portrait,true);

Related

Hiding master UISplitViewController for only certain views

I have a UISplitViewController which has a UINavigationController in the master and a UIViewController in the detail. When the device is orientated into landscape mode I want the normal behaviour to be preserved. I.e. The master gets shown in landscape and hidden in portrait.
However depending what the user clicks in the master depends on which UIViewController is loaded into the detail part of the UISplitViewController. What I would like is for the master to be hidden in landscape mode when a user clicks on a button in the detail UIViewController. The problem is I can't get this to work.
My delegate looks like this (have removed some lines for simpler viewing):
public class SplitControllerDelegate : UISplitViewControllerDelegate {
SplitViewController incomingController;
private bool hideMaster = false;
public override bool ShouldHideViewController (UISplitViewController svc,
UIViewController viewController,
UIInterfaceOrientation inOrientation) {
return hideMaster;
}
public void SetHideMaster(bool value) {
hideMaster = value;
}
}
I then call it from the detail UIViewController like
splitControllerDelegate.SetHideMaster(value);
However nothing changes. I'm unsure of how to make it perform the change? Should the master disappear immediately? What causes the WillHideViewController to fire?
Thanks
Mike
What you're trying to do cannot be done officially. ShouldHideViewController() is called only upon device rotation. So unless you rotate forth and back, your controller won't disappear.
You have various options:
Don't use UIListViewController but some other third party replacement
Use UIViewController containment feature of iOS5 and implement your own split view
Apply a hack to UISplitViewController
About the last point. You should be able to force ShouldHideViewController() being called if you set the Delegate property to NULL and then assign a new delegate. Afterwards, call the WillRotate() method of the split view controller using the current orientation.
I'd go for the 2nd option.
By design you cannot do much with the standard UISplitView, try that third party control :
https://github.com/mattgemmell/MGSplitViewController

UIWebView scrollTo hindered by a return to top

I have a ViewController with a UIWebView, in a Objective-c project for iPad.
When I add html (with loadHtmlString), I try to keep the scroll position it had before the loadHtml, but I cannot help and it returns to the top.
Here are the lines I use:
scrollPosition = [[webView stringByEvaluatingJavaScriptFromString: #"scrollY"] intValue];
[webView loadHTMLString:html baseURL:nil];
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"window.scrollTo(0, %d);",scrollPosition]];
I tested the value 'scrollY' at different locations in my code
and it stays at the value scrollPosition that I want, but when it ends up showing on the screen the WebView is always at the top (with the scrollY value then to 0).
Is there someone who could help me figure out why this happens?
I checked for hours the answers online, also on StackOverflow.
I tried different solutions (like adding in my webview the JavaScript "onclick="scroll(); return false;", but to no avail.
I tried to self-delegate the webView and update the scrollTo in webViewDidFinishLoad, but it seems that webViewDidFinishLoad is not called (the breakpoint is not reached) although I did add in .h in the interface and in the .m in ViewDidLoad the line: webView.delegate=self;
Thank you in advance for any help.
I realized that after recompiling, webViewDidFinishLoad was called after the html was updated, and that I could then scroll to the correct position.
For the self delegation I used in viewDidLoad, it looks so:
webview.delegate = self;
Before updating the html in the webView I calculate the scrolling position with the code:
scrollPosition = [[wbView stringByEvaluatingJavaScriptFromString: #"scrollY"] intValue];
Then, for moving back to this position once the webView has an updated html, I then use:
-(void) webViewDidFinishLoad:(UIWebView *)wbView {
[wbView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"window.scrollTo(0, %d);",scrollPosition]];
}
I found part of the solution through the post below, with the answer of Pawel:
How can I scroll programmatically to the bottom in a uiwebview

Adding a Clickable button on surfaceView

I am implementing a custom surface view, which is called from other activity by setContentView(new SurfaceViewClass(Context)). This class is extending the surfaceView. In the Draw() method which I have added in the surface view, I am displaying an animation that gets triggered, say, every 200 milliseconds, which means that the surfaceview thread gets triggered every 200 msecs.
My requirement is I want to add a button at the bottom of the animation that can respond to events when user has pressed it. How it is possible to do this?
Thank you!
The idea is to have surfaceView(i.e. your graphics) inside a FrameLayout. See the xml layout in the following link.
In the following questions, i have posted the code for the same.
Android:Crash: Binary XML file line : Error inflating class (using SurfaceView)
Let us know if it works!

iphone - how to refresh a uiview with a scrollview?

any advice welcome! :)
My screen design is landscape with text on the left (this is in the main view) and a scrollview on the right (which contains an interactive map image)
The mainviewcontroller contains the scrollview as an outlet.
In the scrollviewcontroller I add a 'map' view into the scrollview.
In the mapviewcontroller I update an array in the appdelegate, depending on the user input.
I would now like to refresh the main uiview that contains the scrollview to display the updated text from the appdel array - whenever the user clicks a button.
You should call your view's -(void)setNeedsDisplay method to cause it to redraw.
[myView setNeedsDisplay];
See Apple's reference documentation here: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html%23//apple_ref/doc/uid/TP40006816-CH3-BBCCADHC
You have to call viewWillAppear from the other viewcontroller

UIButton has to be tapped repeatedly before touchUpInside fires

I have two UIButtons (start and dismiss), contained by a UIView, contained by an outer UIView.
There is nothing special about the buttons.
This is all done in a xib file.
For one of the buttons, it just works.
For the other, when the code is running (simulator or on the iPad doesn't matter), a touchUpInside message is sent to the corresponding controller only on about 10% of taps. tap-tap-taptaptap-tap...tap-tapFIRE. Sometimes tapping slowly and methodically works better. Sometimes.
When it does finally fire, the message (dismissWindow:) is called/received/processed correctly.
The button has a referencing IBOutlet ("dismiss", although I've tried it both with and without one).
The button, the view and the parent view are all "User interaction enabled" and not hidden.
I've tried with the button both on the parent view, and on the subview.
I've tried with the action set to the view container, and to First Responder.
I've ensured that the button is in front.
Is there some urban legend about dodgy and/or finicky UIButtons on the iPhone/iPad? Am I missing some setting someplace?
The other button on the view, Buttons in other xib files, or those created dynamically work as expected. It is simply this one xib file and this one button.
.h
UIButton *dismiss;
...
#property (nonatomic,retain) IBOutlet UIButton *dismiss;
.m
#synthesize ..., dismiss, ...;
...
-(IBAction)dismissWindow:(id)sender {
[[controller detailViewController] dismissWaitView:self];
[self removeFromSuperview];
}
So I throw this out to the collective consciousness. What can I try?
TIA,
rip
In the end, what I noticed was that the UIButton was of type "custom" and the text was "Done" and the style was "Done". Changing any one of those was sufficient to make the button work as I expected it to.
I changed the text from "Done" to "Finished", and it suddenly started working.

Resources