monotouch rotate in landscapemode and portrait mode - iphone

i am new to iPad developer,
i have created two or three iPad application in objective c using Xcode 4.
but now i want to create iPad application using Monodeveloper tool in C# language...
in which, i want to shift my tableView in orientation,
i searched in google but i didn't got any syntax.
for detail see my screen shot...
in first image (portrait mode) my Table is at extremeLeft , in second image (landscape mode) i want my table to be at extreme right..
how should i do this ?
i created tableview programatically, here is the code snippet,
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
Gainer(); //method call
UITableView Table=new UITableView();
Table.Frame=new RectangleF(20,200,400,400);
Table.Source=new TableViewDataSource(TopGainer); //passing parameter to tableview datasource
this.View.AddSubview(Table);
}
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
// Return true for supported orientations
return true;
}
Any help will be appreciated.
Thanks In Advance !!

You can override the WillRotate method and apply the exact position you want, in every case, based on the values that UIScreen.MainScreen provides. E.g.
public override void WillRotate (UIInterfaceOrientation toInterfaceOrientation, double duration)
{
switch (toInterfaceOrientation) {
case UIInterfaceOrientation.LandscapeLeft:
case UIInterfaceOrientation.LandscapeRight:
Table.Frame = new RectangleF (UIScreen.MainScreen.Bounds.Width - 20 - Table.Frame.Width, 200, 400, 400);
break;
case UIInterfaceOrientation.Portrait:
case UIInterfaceOrientation.PortraitUpsideDown:
Table.Frame = new RectangleF (20, 200, 400, 400);
break;
}
base.WillRotate (toInterfaceOrientation, duration);
}

Related

How can I make sure my Xamarin.Forms iOS custom renderer of my entry uses the element's width?

In my Xamarin.Forms application I use a custom renderer for entries, since I want them to be made of a single, bottom border. The problem is that I can't find out the right code to make the custom renderer use the element's width. Currently, the situation is like this:
As you can see, the bottom border goes far beyond the real element's width, but I don't understand why. Here I found something, but still I don't understand how to fix this and why this happens. My current code for the renderer class is:
public class CustomEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.BorderStyle = UITextBorderStyle.None;
var view = Element as CustomEntry;
var borderLayer = new CALayer
{
Frame = new CGRect(0f, Frame.Height + 5, Frame.Width, 1f),
BorderColor = UIColor.Gray.CGColor,
BackgroundColor = UIColor.Magenta.CGColor,
BorderWidth = 13,
MasksToBounds = true
};
Control.Layer.AddSublayer(borderLayer);
}
}
}
The problem seems to be in that Frame.Width. If I set it to 100, for example, the width of the bottom line of the entry is set to 100, but the problem is that, doing so, I'm not able to horizontally center the line. I want this outcome:

WKWebView on macOS cuts off top

I placed a WKWebView inside a NSView with a y coordinate > 0. After loading a page (no matter which one) it either immediately cuts off the top or it shows the top for a second and then jumps down the page (by doing so cutting off the top).
What's more is that when I scroll up I get a glimpse of the top portion but it bounces back not allowing me to actually scroll to the very top.
No changes have been made to the WKWebView. What I noticed is, that the smaller y the smaller the portion which is cut off.
The WKWebView has been added via the Interface Builder.
How can I make the WKWebView show the top of the website? I'm using Swift.
This is what it looks like:
This is what the actual website looks like (notice the visible navigation section):
Okay, I had the same problem as you! Check your view's frame on construction and, if it's not starting at 0,0, make sure that the parent view doesn't auto resize the subviews. I tried to keep my code sample to the bare minimum. (note that webConfig.AllowsAirPlayForMediaPlayback isn't required in this sample)
Here's a working example. You can switch the view to be full frame in the window or positioned as a smaller view in the parent. I set the window to be 1024x768 in IB.
You can easily convert this code to Swift.
The key is to not autoresize the subviews if the view is being placed at an offset other than 0,0.
quick sample:
//#define USE_FULL_WINDOW // uncomment this to fit webview full window
using System;
using AppKit;
using Foundation;
using WebKit;
using CoreGraphics;
using System.Diagnostics;
namespace WkWebTest
{
public class MediaView : NSView
{
private WKWebView webView;
public MediaView(CGRect frame)
: base(frame)
{
#if USE_FULL_WINDOW
this.AutoresizesSubviews = true;
this.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable;
#endif
WKWebViewConfiguration webConfig = new WKWebViewConfiguration();
webConfig.AllowsAirPlayForMediaPlayback = true;
this.webView = new WKWebView(new CGRect(0, 0, frame.Width, frame.Height), webConfig);
this.webView.AutoresizesSubviews = true;
this.webView.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable;
this.AddSubview(this.webView);
string url = "http://www.apple.com";
Debug.WriteLine("LoadUrl: " + url);
var request = new NSUrlRequest(new NSUrl(url));
this.webView.LoadRequest(request);
}
public override bool IsFlipped { get { return true; } }
}
public partial class ViewController : NSViewController
{
private MediaView mediaView;
public ViewController(IntPtr handle) : base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
#if USE_FULL_WINDOW
float mediaViewLeft = 0;
float mediaViewTop = 0;
nfloat mediaViewWidth = View.Frame.Width;
nfloat mediaViewHeight = View.Frame.Height;
#else
float mediaViewLeft = 511;
float mediaViewTop = 112;
nfloat mediaViewWidth = 475;
nfloat mediaViewHeight = 548;
#endif
this.mediaView = new MediaView(new CGRect(mediaViewLeft, mediaViewTop, mediaViewWidth, mediaViewHeight));
this.View.AddSubview(mediaView);
}
// boiler plate code generated by Xamarin
public override NSObject RepresentedObject
{
get
{
return base.RepresentedObject;
}
set
{
base.RepresentedObject = value;
// Update the view, if already loaded.
}
}
}
}

Size classes on Modal Views

I am trying to set different constraints for iPad and iPhone (4'').
I have set Regular Height and Compact width constraints for iPhone. But these constraints are shown on 7.9'' iPad, 9.7'' iPad.
These constraints are for a modal view.
How do i make my Regular Height and Compact width constraints limit to my iPhones only.
Because the form sheet presentation on iPad is compact width and regular height, It is taking those constraints.
Formsheet ios 8 constraints are same as iphones constraints
The solution is to override traitCollection in the Presented view controller
override var traitCollection: UITraitCollection
{
if UIDevice.isIPad()
{
let traits = UITraitCollection(horizontalSizeClass: UIUserInterfaceSizeClass.Regular)
let traits2 = UITraitCollection(verticalSizeClass: UIUserInterfaceSizeClass.Regular)
let traitCollection = UITraitCollection(traitsFromCollections: [traits, traits2])
return traitCollection
}
else
{
return super.traitCollection
}
}
As a note, iOS Docs have this warning for traitCollection:
Use the traitCollection property directly. Do not override it. Do not provide a custom implementation.
With that known, here's an Obj-C solution which combines super traits w/ updated horizontal/vertical traits:
- (UITraitCollection *)traitCollection {
UITraitCollection *traitCollection = [super traitCollection];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
UITraitCollection *horizontalTraitCollection = [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular];
UITraitCollection *verticalTraitCollection = [UITraitCollection traitCollectionWithVerticalSizeClass:UIUserInterfaceSizeClassRegular];
traitCollection = [UITraitCollection traitCollectionWithTraitsFromCollections:#[traitCollection, horizontalTraitCollection, verticalTraitCollection]];
}
return traitCollection;
}

how to set orientation for each scene in unity3d

I have 4 scenes in my game
I need to set scene 1 and scene 3 in landscape mode, scene 2 and scene 4 in portrait mode
how can I do this?
please help me out...
I'm searching for a long time but couldn't find out the answer
You can have a script that checks for the actual level and changes the orientation in according to the retrieved value.
As an example:
function Start(){
if (Application.LoadedLevel == 1)
Screen.orientation = ScreenOrientation.LandscapeLeft;
else if (Application.LoadedLevel == 2)
Screen.orientation = ScreenOrientation.Portrait;
//...
}
More info about usage and orientation values.
Since around Unity 5.3 there is a new API for getting the current scene.
This example forces the screen orientation on mobile devices to portrait on a scene called "GameView" and landscape otherwise.
using UnityEngine;
using UnityEngine.SceneManagement;
public class ScreenOrientationScript : MonoBehaviour {
void Start () {
if (Application.isMobilePlatform == true) {
if (SceneManager.GetActiveScene().name == "GameView") {
Screen.orientation = ScreenOrientation.Portrait;
} else {
Screen.orientation = ScreenOrientation.Landscape;
}
}
}
}
Sample iOS setting to allow orientations
Unity uses single/sole activity for ALL Levels/Scenes, which is com.unity3d.player.UnityPlayerActivity, as can be found in AndroidManifest.xml file.
So all you need do is to specify the orientation in the Player Setting Inspector (Default Orientation part):

Animation Problem

i have a view class and a custom button class. view has 4 instances of these custom buttons.
custom button class fires an event. view class uses this event and start animation to resize all buttons. it maximize the event generator button and minimize others. animation for the event generator button does not work. for other buttons, animation works. animation for the event generator button behaves like the animation time is zero. it immediately maximize the button.
it seems this code just animates position, not the size. how can i animate the size parameter?
is it bug or it is normal? or is it a ui thread problem?
this code is from view class;
void HandleButtonClick (object sender, EventArgs e)
{
BestButton[] buttons = { best1, best2, best3, best4 };
UIView.BeginAnimations ("AnimateLabel");
UIView.SetAnimationDuration (2);
UIView.SetAnimationDidStopSelector (new Selector ("didFinishAnimation:"));
UIView.SetAnimationDelegate (this);
var max = new RectangleF (0, 0, 320, 460);
var min = new RectangleF (0, 0, 0, 0);
foreach (var item in buttons) {
if (sender == item)
item.Frame = max;
else
item.Frame = min;
}
UIView.CommitAnimations ();
}
i found the solution. i deleted this line and everything works now.
UIView.SetAnimationDelegate (this);