Carplay: UI is overlapping with left sidebar - ios

I am currently working on arplay UI. But when run the Carplay, UI is overlapping with left side bar. I have attached the screen shot as well.
UIWindowScene windowScene = new UIWindowScene(session, connectionOptions);
var ContainerViewController = UtilityIOS.CPStoryboard.InstantiateViewController("ContainerVC") as ContainerVC;
var registerController = UtilityIOS.CPStoryboard.InstantiateViewController("CarplayNavigationDashboardVC") as UINavigationController;
ContainerViewController.AddChildViewController(registerController);
registerController.View.Frame = new CGRect(0, 0, ContainerViewController.View.Frame.Width, ContainerViewController.View.Frame.Height);
ContainerViewController.View.AddSubview(registerController.View);
registerController.DidMoveToParentViewController(ContainerViewController);
this.Window = new UIWindow(windowScene);
// this.Window.Frame = new CGRect(40, 0, UIScreen.MainScreen.Bounds.Width - 40, UIScreen.MainScreen.Bounds.Height);
this.Window.RootViewController = ContainerViewController;
this.Window.MakeKeyAndVisible();

Related

UILabel with Image and text in iOS(Xamarin)

I am making UILabel with Image and text inside that.I try many thing like below.
Try 1 :
Using this code
var textAttchment = new NSTextAttachment();
textAttchment.Image = UIImage.FromBundle("location_grey_icon");
var attachmentString = NSAttributedString.FromAttachment(textAttchment);
var attributedString = new NSMutableAttributedString(lbl_inr.Text.ToString());
this.lbl_inr.AttributedText = attributedString;
But it only display the Text not the image.
Try 2:
using this code
var attchment = new NSTextAttachment();
attchment.Image = UIImage.FromBundle("location_grey_icon");
attchment.Bounds = new CGRect(0, -1, 13, 13);
var intiliazeText = this.text_inr.AttributedText;
var newText = new NSMutableAttributedString(intiliazeText);
newText.Append(NSAttributedString.CreateFrom(attchment));
this.text_inr.AttributedText = newText;
it is display the Image and Text both.
Output :
What I want :
but my requirement is to I want to set image before the Text so first Image and then Text.
Any help be Appreciated.
Your requirement is very specific, the best way to do this would be with a custom control.
UIView + Label + UIImageView
and there you could set your bounds to your needs. With the designer this is a simple task.
Or you could try with a UITextField, removing the borders and disabling it. Then adding a UIImageView as the RightView (or LeftView as you wish).
var textEdit = new UITextField (new CGRect (15, 100, 200, 30));
textEdit.Enabled = false;
textEdit.Text = "Hello from Xamarin";
var xamImageView = new UIImageView (new CGRect (0,0, 25, 25));
xamImageView.Image = UIImage.FromBundle ("xamagon");
textEdit.RightView = xamImageView;
textEdit.TextAlignment = UITextAlignment.Right;
textEdit.RightViewMode = UITextFieldViewMode.Always;
textEdit.BorderStyle = UITextBorderStyle.None;
Result:
Hope this helps!
Using below code I manage
var attchment = new NSTextAttachment();
attchment.Image = UIImage.FromBundle("location_grey_icon");
attchment.Bounds = new CGRect(0, -2, 14, 14);
var newText = new NSMutableAttributedString();
newText.Append(NSAttributedString.CreateFrom(attchment));
NSAttributedString s = new NSAttributedString(item.Total.ToString());
newText.Append(s);
this.lbl_inr.AttributedText = newText;
Output :

How to create UIStackView from code correctly

I can't understand why this layout won't render the way i need it. Completing the requirement on android with linearlayouts should be equivalent to this?
What i get:
What i need:
My code:
// my stackview only renders at all if i pass any height > 0 && width > 0,
// but i would love this to be as small as possible, given that all children
// are rendered.
var stackView = new UIStackView(View.Frame);
stackView.Axis = UILayoutConstraintAxis.Vertical;
stackView.Distribution = UIStackViewDistribution.Fill;
foreach (var deviceVm in devices)
{
// i would prefer this not to have a rect parameter and scale as needed.
var descriptionLabel = new UILabel(new CGRect(0, 0, View.Bounds.Width, 20));
descriptionLabel.Text = deviceVm.Description;
descriptionLabel.TextColor = UIColor.Blue;
descriptionLabel.ContentMode = UIViewContentMode.ScaleToFill;
stackView.AddArrangedSubview(descriptionLabel);
}
// i assume this should make it as small as possible, as big as necessary?
stackView.SizeToFit();
var scrollView = new UIScrollView(View.Frame);
scrollView.BackgroundColor = UIColor.Yellow;
scrollView.AddSubview(stackView);
View.AddSubview(scrollView);
Can someone spot a mistake i am doing here? Am i configuring the StackView incorrectly or is this control not the equivalent of LinearLayout(android) / StackPanel(wpf) ?
PS: Sorry for eye cancer paint pictures.

Screen mirror not behaving as expected (Swift)

I'm trying to implement some simple screen mirroring in my swift application but I'm getting undesired behavior. When my code executes, the external display gets the phone view but the iphone screen goes black. Also in the external view it's filled in with black. Here's a screenshot:
Here's my code to setup the external view:
func initializeExternalScreen(external: UIScreen){
self.mirroredScreen = external;
// Find max resolution
var max = CGSize()
var maxScreenMode = UIScreenMode()
for current in self.mirroredScreen.availableModes {
if (current.size.height > max.height || current.size.width > max.width) {
max = current.size;
maxScreenMode = current;
}
}
self.mirroredScreen.currentMode = maxScreenMode;
self.mirroredWindow = UIWindow(frame: self.mirroredScreen.bounds)
self.mirroredWindow.hidden = false
self.mirroredWindow.layer.contentsGravity = kCAGravityResizeAspect
self.mirroredWindow.screen = self.mirroredScreen
self.mirroredScreenView = UIView(frame: self.mirroredScreen.bounds)
self.mirroredScreenView.addSubview(self.view)
self.mirroredWindow.addSubview(self.mirroredScreenView)
}
Any ideas?

nativescript marshalling error

I seem to be getting a strange problem when marshaling the following native iOS code to nativescript:
CGRect keyboardRect = CGRectMake(0, 0, self.view.frame.size.width, 216);
AGEmojiKeyboardView *emojiKeyboardView = [[AGEmojiKeyboardView alloc] initWithFrame:keyboardRect
dataSource:self];
emojiKeyboardView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
emojiKeyboardView.delegate = self;
self.textView.inputView = emojiKeyboardView;
The equivalent I came up with is the following:
var keyboardRect = CGRectMake(0, 0, platform.screen.mainScreen.widthPixels, 216);
var emojiKeyboardView = new AGEmojiKeyboardView();
emojiKeyboardView.frame = keyboardRect;
emojiKeyboardView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
emojiKeyboardView.delegate = this;
views.textInput.ios.inputView = emojiKeyboardView;
where platform is just require("platform"); and views.textInput is a view to which I need to set the inputView to AGEmojiKeyboardView.
I really don't understand where I went wrong. All that appears is a grey keyboard with no content.
EDIT:
I changed the js code to the following:
var keyboardRect = CGRectMake(0, 0, uiView.view.frame.size.width, 216);
var emojiKeyboardView = new AGEmojiKeyboardView(keyboardRect, uiView);
emojiKeyboardView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
emojiKeyboardView.delegate = uiView;
views.textInput.ios.inputView = emojiKeyboardView;
where uiView is just page.ios and something seems to happen now, but still not the intended result. An exception is thrown, namely the following: -[UIViewControllerImpl emojiKeyboardView:imageForSelectedCategory:]: unrecognized selector sent to instance 0x7e6bff60
As NativeScript has TypeScript as first-class member somethings are really easier to do with TS. For example you can also use the META-Generator
Simply run this two lines to generate metadata & typings for your CocoaPod (and all other Objective-C files) and you won't have to worry about the right syntax.(still you will need to know the basic rules)
TNS_DEBUG_METADATA_PATH="$(pwd)/metadata" tns build ios [--for-device] [--release]
TNS_TYPESCRIPT_DECLARATIONS_PATH="$(pwd)/typings" tns build ios [--for-device] [--release]
Also if you want to createa a custom view the best variant is using NativeScript placeholder with creatingView
As for the syntax it shouldb look similar to this but still you will have to create your own ViewController and as the author says - conform to AGEmojiKeyboardViewDataSource and AGEmojiKeyboardViewDelegate protocol.
var frame = require('ui/frame');
var page;
function onLoaded(args) {
page = args.object;
}
exports.onLoaded = onLoaded;
function onCreatingView(args) {
setTimeout(function() {
var uiView = page.ios.view; // replace with own UIView and conform to AGEmojiKeyboardViewDataSource and AGEmojiKeyboardViewDelegate protocol.
var frame = {origin: {x:0, y:0}, size: {width: uiView.frame.size.width, height:600}};
var emojiView = AGEmojiKeyboardView.alloc().initWithFrameDataSource(frame, uiView);
emojiView.autoresizingMask = UIView.UIViewAutoresizing.UIViewAutoresizingFlexibleHeight;
emojiView.delegate = uiView;
var textContainer = NSTextContainer.alloc().initWithSize({width: 80, height: 180});
var frame = {origin: {x:0, y:0}, size: {width: 100, height:220}};
var textView = UITextView.alloc().initWithFrameTextContainer(frame, textContainer);
textView.inputView = emojiView;
args.view = textView;
}, 500);
}
exports.onCreatingView = onCreatingView;
page.xml
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="onLoaded">
<StackLayout>
<Placeholder creatingView="onCreatingView" id="placeholder-view"/>
</StackLayout>
</Page>
I could be mistaken, but I don't think you are using marshalling properly.
The documentation states:
AGEmojiKeyboardView *emojiKeyboardView = [[AGEmojiKeyboardView alloc] initWithFrame:keyboardRect dataSource:self];
So your {N} version should be something like this:
var emojiKeyboardView = AGEmojiKeyboardView.alloc().initWithFrameDataSource(keyboardRect, uiView);
This is a great blog-post on how to create plugins based on 3rd party libraries for nativescript. It also explains step-by-step how this type of marshalling is done.
http://fluentreports.com/blog/?p=167

UIDynamicAnimator Shake with spring effect

I'm trying to replace my core animation shake effect in this code
let shake = CAKeyframeAnimation(keyPath: "position.x")
shake.values = [0, 20, -20, 20, -15, 15, -5, 5, 0]
shake.keyTimes = [0, 1/10.0, 3/10.0, 5/10.0, 6/10.0, 7/10.0, 8/10.0, 9/10.0, 1]
shake.duration = 0.4
shake.additive = true
circlesContainer.layer.addAnimation(shake, forKey: "shakeYourBooty")
with the spring effect by combining UIPushBehavior and UIAttachmentBehavior like this
if origCirclesContainerCenter == nil {
origCirclesContainerCenter = circlesContainer.center
}
shake = UIDynamicAnimator(referenceView: self.view)
let push = UIPushBehavior(items: [circlesContainer], mode: UIPushBehaviorMode.Continuous)
push.pushDirection = CGVectorMake(100.0, 0.0)
print(origCirclesContainerCenter)
let attachement = UIAttachmentBehavior(item: circlesContainer, attachedToAnchor:origCirclesContainerCenter!)
attachement.frequency = 3.0
attachement.damping = 0.5
shake.addBehavior(attachement)
shake.addBehavior(push)
The problem is the attachment behavior doesn't seem to work because the view does not spring back to the original position after being pushed. The animation actually pushes the view position to the right 100 points. origCirclesContainerCenter is the same on every call. Any idea?
I changed the push behavior mode to UIPushBehaviorMode.Instantaneous to fix the problem.

Resources