I have a UINavigationController which I'm using quite happily. However I want to push a UIViewController onto the screen but I want it to be smaller than the existing one. The code I have below doesn't resize the new ViewController. It's still displayed full screen.
public void DisplayEditWindow () {
editViewController = new EditViewController(UITableViewStyle.Grouped);
editViewController.View.Frame = new RectangleF(0, 0, 500, 600);
navigationController.PushViewController (editViewController, true);
}
I'm sure I'm doing something a bit daft but I cant see what. All help greatly appreciated.
mike
UINavigationController does not work in this way. PresentModalViewController would not work either, you would end up with a black screen where the other view was (unless you use a specific transition that works on iPad only).
The only way you can get this effect is to add a new sub-view to your existing view. This is certainly more complicated, as you would have to manage dismissing it yourself and program any transition animations manually.
Related
I have a simple iPhone app with a simple view and a custom view as a child. The child is just a square painted on the main view.
I need to track a touch event that enters this child view but from a touch that started outside the view.
What I've tried so far is to add the TouchesBegin/TouchesMoved events to the parent view. Also tried to add the to the child controls directly but that doesn't track any touches that are not initiated within that control.
The questions are:
a) can I get the control from Position somehow?
b) is this the best way doing this, or is there another way?
Again, I include this video of GamePlay for the game I'm trying to port (on my spare time). It's not a promotion attempt but illustrates what I'm trying to accomplish. I wrote the Win8 and WP7 version of the game so I'm not trying to copy another persons work here. :) Don't watch it if you don't want to know what game it is. The question is still valid without watching this.
http://www.youtube.com/watch?v=13IczvA7Ipo
Thanks
// Johan
I stumbled on the answer myself. In the parent I override TouchesMoved (and Begin and Ended not shown here).
I then iterate the subviews and chech if it's the view I'm looking for by type and then check if the Frame contains the point. The code below is just concept of course.
public override void TouchesMoved (NSSet touches, UIEvent evt)
{
base.TouchesMoved (touches, evt);
UITouch touch = touches.AnyObject as UITouch;
if (touch != null) {
var rp = touch.LocationInView (touch.View);
foreach(var sv in this.View.Subviews)
{
if(!(sv is LetterControl))
continue;
if(sv.Frame.Contains (rp))
{
Console.WriteLine("LetterControl found");
}
}
}
}
NOTE: There are two similar SO questions (1) (2), but neither of them provides an answer.
TL;DR: How can one dismiss the keyboard in a MonoTouch.Dialog by letting the user touch any empty space in the view?
I'm writing an app using MonoTouch.Dialog and a UITabBarController. One of my tabs is "Settings"...
When the user starts typing, the keyboard obstructs the tabbar...
Using MonoTouch.Dialog, the only way to dismiss the keyboard is to go to the last field and press the "return" key. Considering the fact that the user cannot press any tab until the keyboard is gone, I would like a better way to do it. Namely, to dismiss if the user taps anywhere else on the screen.
Without MonoTouch.Dialog, it's a snap: simply override TouchesBegan and call EndEditing. But this doesn't work with MT.D. I've tried subclassing DialogViewController and overriding TouchesBegan there, but it doesn't work. I'm currently at a loss.
Or, I wonder, would I be better off ditching the tabbar so I can use a UINavigationController with a "Back" button on top, which won't be hidden by the keyboard?
I suggest you use a tap gesture recognizer that will not cause interference with the TableView event handlers:
var tap = new UITapGestureRecognizer ();
tap.AddTarget (() => dvc.View.EndEditing (true));
dvc.View.AddGestureRecognizer (tap);
tap.CancelsTouchesInView = false;
You missed my question about it also: Can the keyboard be dismissed by touching outside of the cell in MonoTouch.Dialog?
:-)
This is my #1 feature request for MonoTouch.Dialog.
To answer your question: No. It is not possible. I have searched and asked around and have not found any answers.
I assume because it is just a sectioned (grouped) table and if it wasn't sectioned, there wouldn't be any spot to click. However, that is just my speculation.
I wish that miguel or someone that works on monotouch would answer this and say if it is even possible. Possibly a future enhancement?
I figured out a workaround that satisfies me well enough, so I'm answering my own question.
// I already had this code to set up the dialog view controller.
var bc = new BindingContext (this, settings, "Settings");
var dvc = new DialogViewController (bc.Root, false);
// **** ADD THIS ****
dvc.TableView.DraggingStarted += (sender, e) => {
dvc.View.EndEditing (true);
};
This will dismiss the keyboard whenever the user drags the view a little bit. There's no touch event I could find associated with the tableview, so this is the next best thing. I'd welcome any other ideas. Cheers!
One workaround to use the dragging gesture instead of the tap as proposed (that do not interfere with the table view gestures) is to override MonoTouch.Dialog.DialogViewController.SizingSource (or MonoTouch.Dialog.DialogViewController.Source if you don't want uneven rows) and give it to the DialogViewController. I don't know if it is very clean or safe.
public class CustomTableViewSource : MonoTouch.Dialog.DialogViewController.SizingSource
{
public CustomTableViewSource(MonoTouch.Dialog.DialogViewController dvc) : base(dvc)
{
}
public override void DraggingStarted(UIScrollView scrollView)
{
base.DraggingStarted(scrollView);
if (scrollView != null)
{
scrollView.EndEditing(true);
}
}
}
I need to be able to hide the navbar and tabbar when I tap on the view and show it again when tapped again. Is this possible in Monotouch?
Anything that is possible with the native platform is possible with MonoTouch.
There are dozens of ways of achieving this. Perhaps the simplest thing to do is to create your own UIViewController that will host only the information you want and calling:
var myNewController = new MyNewController ()
myNewController.View.TouchDown += delegate {
myNewController.DismissViewControllerAnimated (false);
};
PresentModalViewController (yourNewController, false);
Then your myNewController must contain some code to add the actual contents that you want to show in full screen.
I have created storyboard using following instructions
http://docs.xamarin.com/ios/tutorials/Introduction_to_iOS_5#Storyboards
It works as expected.
Then I added new button to MonkeyController and new ViewController to storyboard. This is the code I tried to use in button's click event
partial void btnClicked (NSObject sender)
{
UINavigationController ctrl = this.ParentViewController;
var screen = new TableRowViewController();
ctrl.PushViewController(screen, true);
}
It opens TableRowViewController, but it's background is black and it does not show any modifications I made on it on storyboard.
Can you help me with this?
I'm no expert yet, but it has been my experience trying to get it to work properly that if one of the sides of the split-view is black, then there is a segue that is illegal.
Hope that helps...
Does any one have an idea how to access the UIScroller class , which is the default subview of UIWebView ?
I want to handle the touches, zooming , panning and scrolling features inside the webview .
Thanks..
I know this thread is old but if anyone comes across it there's a new way.
As of iOS 5 UIWebView now has a property called scrollView which you can't replace but you can set the properties of it. Most people just want to disable zooming/bouncing/scrolling all together which can be done by setting the properties of the scrollView for example if webview is a UIWebView:
webview.scrollView.bounces = NO; //Disables webview from bouncing
webview.scrollView.minimumZoomScale = webview.scrollView.maximumZoomScale = 1.0; //Forces zoom to be at 1 (can be whatever you fancy) and disables zooming
webview.scrollView.bouncesZoom = NO; //Disables bouncing when zooming exceeds minimum or maximum zoom
I suppose you could set the delegate for the scrollView if you want more control, though to be on the safe side you might want to store the original delegate and call its methods appropriately in your custom delegate.
Handling the touches would be more difficult since you can't replace the scrollView to provide your own handlers. Best you could do is add some gesture recognizers as part of the UIView and try to handle them there, but I think UIWebView will still receive the events. Alternatively in iOS 5 they let you access the gesture recognizers directly on UIScrollView.
You can find this by going like this:
[webview objectAtIndex:0]
That should be where it is. If not, put this in your code somewhere and run the program to search for the index of the UIScroller, and replace the 0 above with that index:-
for (UIView *subview in [webView subviews]){
NSLog(#"subviews of webView : %#", [[subview class] description]);
}