private void ScrollTheView(bool move) { if (_frameBaseY == null) { _frameBaseY = View.Frame.Y; } // scroll the view up or down UIView.BeginAnimations(string.Empty, System.IntPtr.Zero); UIView.SetAnimationDuration(0.3); CGRect frame = View.Frame; if (move) { frame.Y += _scrollDistance; } else { frame.Y = _frameBaseY.Value; _scrollDistance = 0; } View.Frame = frame; UIView.CommitAnimations(); }
/// <summary> /// Wraps the specified <see cref="UIStackView"/> and generates a <see cref="UIView"/>. /// </summary> /// <param name="stackView">The specified <see cref="UIStackView"/>.</param> /// <param name="width">The specified, optional width of the target <see cref="UIView"/>.</param> /// <param name="height">The specified, optional height of the target <see cref="UIView"/>.</param> /// <param name="horizontalConstraint">The constraint attribute on the horizontal axis.</param> /// <param name="verticalConstraint">The constraint attribute on the vertical axis.</param> /// <returns>The generated <see cref="UIView"/>.</returns> public static UIView WrapStackView(UIStackView stackView, nfloat?width, nfloat?height, NSLayoutAttribute horizontalConstraint, NSLayoutAttribute verticalConstraint) { var wrapper = new UIView(); if (width.HasValue) { wrapper.WidthAnchor.ConstraintEqualTo(width.Value).Active = true; } if (height.HasValue) { wrapper.HeightAnchor.ConstraintEqualTo(height.Value).Active = true; } var centerXConstraint = NSLayoutConstraint.Create(stackView, horizontalConstraint, NSLayoutRelation.Equal, wrapper, horizontalConstraint, 1f, 0f); var centerYConstraint = NSLayoutConstraint.Create(stackView, verticalConstraint, NSLayoutRelation.Equal, wrapper, verticalConstraint, 1f, 0f); wrapper.AddSubview(stackView); wrapper.AddConstraints(new[] { centerXConstraint, centerYConstraint }); wrapper.TranslatesAutoresizingMaskIntoConstraints = false; wrapper.SizeToFit(); wrapper.LayoutIfNeeded(); ConfigureStackViewAccessibilityAttributes(wrapper); return(wrapper); }
protected override bool Validating() { if (_defaultColor == null) { var firstRelationship = _sourceBindingRelationships.FirstOrDefault(); if (firstRelationship.Value != null) { var firstView = firstRelationship.Value.FirstOrDefault(); if (firstView != null) { _defaultColor = firstView.Layer.BorderColor; _defaultWidth = firstView.Layer.BorderWidth; } } } if (_sourceBindingRelationships == null) { return(false); } foreach (var textView in _sourceBindingRelationships.SelectMany(sourceBindingRelationship => sourceBindingRelationship.Value)) { textView.Layer.BorderColor = _defaultColor; textView.Layer.BorderWidth = _defaultWidth.GetValueOrDefault(); } return(true); }
protected BaseTableViewSource(UITableView tableView, IReactiveNotifyCollectionChanged <TViewModel> collection, Foundation.NSString cellKey, nfloat height, nfloat?heightHint = null, Action <UITableViewCell> initializeCellAction = null) : base(tableView, collection, cellKey, (float)height, initializeCellAction) { tableView.RowHeight = height; tableView.EstimatedRowHeight = heightHint ?? tableView.EstimatedRowHeight; }
public static IEnumerable <FluentLayout> FullSizeOf( [NotNull] this UIView view, [NotNull] UIView parent, [NotNull] IUILayoutSupport topLayoutGuide, [NotNull] IUILayoutSupport bottomLayoutGuide, [CanBeNull] nfloat?margin = null) { if (view == null) { throw new ArgumentNullException(nameof(view)); } if (parent == null) { throw new ArgumentNullException(nameof(parent)); } if (topLayoutGuide == null) { throw new ArgumentNullException(nameof(topLayoutGuide)); } if (bottomLayoutGuide == null) { throw new ArgumentNullException(nameof(bottomLayoutGuide)); } return(FullSizeOf(view, parent, topLayoutGuide, bottomLayoutGuide, new Margins((float)margin.GetValueOrDefault(DefaultMargin)))); }
protected ReactiveTableViewSource(UITableView tableView, nfloat height, nfloat?heightHint = null) : base(tableView) { tableView.RowHeight = height; tableView.EstimatedRowHeight = heightHint ?? tableView.EstimatedRowHeight; this.WhenAnyValue(x => x.Data).IsNotNull().Select(x => x.Count == 0).Subscribe(_isEmptySubject.OnNext); }
/** * Close the Menu component with animation options. * - Parameter duration: The time for each view's animation. * - Parameter delay: A delay time for each view's animation. * - Parameter usingSpringWithDamping: A damping ratio for the animation. * - Parameter initialSpringVelocity: The initial velocity for the animation. * - Parameter options: Options to pass to the animation. * - Parameter animations: An animation block to execute on each view's animation. * - Parameter completion: A completion block to execute on each view's animation. */ public void Close(double duration = 0.15, double delay = 0, nfloat?usingSpringWithDamping = null, nfloat initialSpringVelocity = default(nfloat), UIViewAnimationOptions options = default(UIViewAnimationOptions), Action <UIView> animations = null, Action <UIView> completion = null) { usingSpringWithDamping = usingSpringWithDamping ?? 0.5f; if (IsEnabled) { disable(); switch (Direction) { case MenuDirection.Up: { closeUpAnimation(duration, delay, usingSpringWithDamping.Value, initialSpringVelocity, options, animations, completion); } break; case MenuDirection.Down: { closeDownAnimation(duration, delay, usingSpringWithDamping.Value, initialSpringVelocity, options, animations, completion); } break; case MenuDirection.Left: { closeLeftAnimation(duration, delay, usingSpringWithDamping.Value, initialSpringVelocity, options, animations, completion); } break; case MenuDirection.Right: { closeRightAnimation(duration, delay, usingSpringWithDamping.Value, initialSpringVelocity, options, animations, completion); } break; } } }
void FlipView_Scrolled(object sender, EventArgs e) { var pageWidth = this.Frame.Size.Width; var page = (int)Math.Floor((this.ContentOffset.X - pageWidth / 2) / pageWidth) + 1; this.PageControl.CurrentPage = page; //Debugger.Log(1, "FlipView", page.ToString()); //左右滑动时,不知道目标页是哪个 //只能设置 Next / GoTo 的目标位置 //滚动到目标位置后,把 TargetX 设置为 null //当左右滑动的时候, TargetX 一直是 null,这样就可以判断到底是滑动,还是程序跳转了 if (this.ContentOffset.X == this.TargetX) { this.TargetX = null; } if (TargetX == null) { if (this.PosChanged != null) { this.PosChanged.Invoke(this, new FlipViewPosChangedEventArgs() { Pos = page }); } } }
protected virtual iOSXenkoView CreateView(CGRect bounds, nfloat?contentScaleFactor = null) { // create the xenko game view return(new iOSXenkoView((RectangleF)bounds) { ContentScaleFactor = contentScaleFactor ?? UIScreen.MainScreen.Scale }); }
public static UIFont ToUIFont(this string fontfamilary, nfloat?fontSize = null) { try { return(UIFont.FromName(fontfamilary, fontSize ?? UIFont.SystemFontSize)); } catch { return(UIFont.PreferredBody); } }
public static void ChangeFrame(this UIView control, nfloat?x = null, nfloat?y = null, nfloat?w = null, nfloat?h = null) { x = x ?? control.Frame.X; y = y ?? control.Frame.Y; w = w ?? control.Frame.Width; h = h ?? control.Frame.Height; control.Frame = new CGRect(x.Value, y.Value, w.Value, h.Value); }
/// <summary> /// Resizes the rectangle. /// </summary> /// <returns>The frame.</returns> /// <param name="frame">Frame.</param> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="width">Width.</param> /// <param name="height">Height.</param> internal static CGRect ResizeRect(this CGRect frame, nfloat?x = null, nfloat?y = null, nfloat?width = null, nfloat?height = null) { frame.X = x ?? frame.X; frame.Y = y ?? frame.Y; frame.Width = width ?? frame.Width; frame.Height = height ?? frame.Height; return(frame); }
protected virtual iOSStrideView CreateView(CGRect bounds, nfloat?contentScaleFactor = null) { // create the stride game view var rect = new System.Drawing.RectangleF((float)bounds.X, (float)bounds.Y, (float)bounds.Height, (float)bounds.Width); return(new iOSStrideView(rect) { ContentScaleFactor = contentScaleFactor ?? UIScreen.MainScreen.Scale }); }
/// <summary> /// Делает SizeToFit и задает получившуюся высоту /// </summary> /// <returns>Bottom position of view</returns> /// <param name="view">View.</param> /// <param name = "yPosition">Можно задать позицию, которая будет после выполнения SizeTofit</param> /// <param name = "saveDefaultWidth">Сохраняет значение предустановленной ширины представления</param> /// <param name = "minHeight">Есть возможность задать минимальную высоту. В случае, если высота после SizeToFit будет меньше заданной, будет использоваться minHeight</param> public static nfloat ResizeView(this UIView view, nfloat?yPosition = null, bool saveDefaultWidth = true, float minHeight = 0) { var defaultWidth = view.Frame.Width; view.SizeToFit(); view.ChangeFrame(y: yPosition ?? view.Frame.Y, w: saveDefaultWidth ? defaultWidth : view.Frame.Width, h: (minHeight > 0 && view.Frame.Height < minHeight) ? minHeight : view.Frame.Height); return(view.Frame.Bottom); }
/// <summary> /// Based on iOS settings of text size in General->Accessibility->LargerText. /// This overload was created to better work with memoized functions /// </summary> /// <param name="size"></param> /// <param name="basePreferredSize"></param> /// <returns></returns> private static nfloat GetScaledFontSize(nfloat size, nfloat?basePreferredSize) { //We need to scale the font size depending on the PreferredBody size. This is modified by accessibility settings. //https://developer.xamarin.com/api/member/MonoTouch.UIKit.UIFont.GetPreferredFontForTextStyle/ if (FeatureConfiguration.Font.IgnoreTextScaleFactor) { return(size); } return(size * (basePreferredSize / DefaultUIFontPreferredBodyFontSize) ?? (float)1.0); }
public static void SetDimensions(this _View view, nfloat?width = null, nfloat?height = null) { if (nfloat.IsNaN(width ?? 0) || nfloat.IsNaN(height ?? 0)) { view.Log().ErrorFormat("A view Frame must not be set to [{0};{1}], overriding to [0;0]", width, height); width = 0; height = 0; } view.Frame = new CGRect(view.Frame.X, view.Frame.Y, width ?? view.Frame.Width, height ?? view.Frame.Height); }
public void Goto(int idx) { var offset = this.ContentOffset; offset.X = this.Frame.Size.Width * idx; if (offset.X >= this.ContentSize.Width) { offset.X = 0; } this.TargetX = offset.X; this.SetContentOffset(offset, true); }
public void Next() { var offset = this.ContentOffset; offset.X += this.Frame.Size.Width; if (offset.X >= this.ContentSize.Width) { offset.X = 0; } this.TargetX = offset.X; this.SetContentOffset(offset, true); }
public static IEnumerable <FluentLayout> FullSizeOf( [NotNull] this UIView view, [NotNull] UILayoutGuide safeAreaLayoutGuide, [CanBeNull] nfloat?margin = null) { if (view == null) { throw new ArgumentNullException(nameof(view)); } if (safeAreaLayoutGuide == null) { throw new ArgumentNullException(nameof(safeAreaLayoutGuide)); } return(FullSizeOf(view, safeAreaLayoutGuide, new Margins((float)margin.GetValueOrDefault(DefaultMargin)))); }
public static void Init() { if (_scale.HasValue) { return; } ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => { #if __IOS__ _scale = UIKit.UIScreen.MainScreen.Scale; #elif __MACOS__ _scale = AppKit.NSScreen.MainScreen.BackingScaleFactor; #endif }).ConfigureAwait(false).GetAwaiter().GetResult();; }
public static async Task InitAsync() { if (_scale.HasValue) { return; } var dispatcher = ImageService.Instance.Config.MainThreadDispatcher; await dispatcher.PostAsync(() => { #if __IOS__ || __TVOS__ _scale = UIKit.UIScreen.MainScreen.Scale; #elif __MACOS__ _scale = AppKit.NSScreen.MainScreen.BackingScaleFactor; #endif }).ConfigureAwait(false); }
public static CABasicAnimation ScaleZ(nfloat?scale = null, double?duration = null) { var animation = CABasicAnimation.FromKeyPath("transform.scale.z"); if (scale != null) { animation.To = NSNumber.FromNFloat(scale.Value); } animation.FillMode = Convert.MaterialAnimationFillModeToValue(MaterialAnimationFillMode.Forwards); animation.RemovedOnCompletion = false; animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut); if (duration != null) { animation.Duration = duration.Value; } return(animation); }
public void MaximumReferenceExtendedDynamicRangeColorComponentValueNoMainThread() { if (NSScreen.MainScreen == null) { Assert.Inconclusive("Could not find main screen."); } var called = new AutoResetEvent(false); nfloat?factor = null; var backgroundThread = new Thread(() => { factor = NSScreen.MainScreen.MaximumReferenceExtendedDynamicRangeColorComponentValue; called.Set(); }); backgroundThread.Start(); Assert.IsTrue(called.WaitOne(1000), "called"); Assert.IsTrue(factor.HasValue, "factor"); }
public void BackingScaleFactorNoMainThread() { if (NSScreen.MainScreen == null) { Assert.Inconclusive("Could not find main screen."); } var called = new AutoResetEvent(false); nfloat?factor = null; var backgroundThread = new Thread(() => { factor = NSScreen.MainScreen.BackingScaleFactor; called.Set(); }); backgroundThread.Start(); Assert.IsTrue(called.WaitOne(1000), "called"); Assert.IsTrue(factor.HasValue, "factor"); }
private void OnScrolled(UITableView tableView) { var point = tableView.PanGestureRecognizer.TranslationInView(tableView); var difference = _lastY - point.Y; nfloat?newConstant = null; if (HeaderViewTopConstraint.Constant - difference <= -HeaderView.Frame.Height) { // Stop the adjustment once the header view is off the screen newConstant = -HeaderView.Frame.Height; } else if (HeaderViewTopConstraint.Constant - difference >= 0 && tableView.ContentOffset.Y <= 0) { // Stop the adjustment once the header view is fully in view newConstant = 0; } else { if (difference <= 0 && tableView.ContentOffset.Y <= 0) { // Only move the header view back out if we're at the top newConstant = HeaderViewTopConstraint.Constant -= difference; } else if (difference >= 0 && tableView.ContentOffset.Y >= 0) { // Move the header view out whenever we're scrolling down newConstant = HeaderViewTopConstraint.Constant - difference; } } // Adjust the constraint per the user's scroll if (newConstant.HasValue) { HeaderViewTopConstraint.Constant = newConstant.Value; } // Track the current position _lastY = point.Y; }
public static CABasicAnimation RotateX(nfloat?angle = null, nfloat?rotation = null, double?duration = null) { var animation = CABasicAnimation.FromKeyPath("transform.rotation.x"); if (angle != null) { animation.To = NSNumber.FromDouble(Math.PI * angle.Value / 180.0); } else if (rotation != null) { animation.To = NSNumber.FromDouble(Math.PI * 2 * rotation.Value); } animation.FillMode = Convert.MaterialAnimationFillModeToValue(MaterialAnimationFillMode.Forwards); animation.RemovedOnCompletion = false; animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut); if (duration != null) { animation.Duration = duration.Value; } return(animation); }
//helper method to create constraints based on existing constraints NSLayoutConstraint GetConstraint( NSLayoutConstraint constraint, NSObject object1 = null, NSLayoutAttribute?attribute1 = null, NSLayoutRelation?relation = null, NSObject object2 = null, NSLayoutAttribute?attribute2 = null, nfloat?multiplier = null, nfloat?constant = null) { if (constraint == null) { return(null); } return(NSLayoutConstraint.Create( object1 ?? constraint.FirstItem, (attribute1 == null) ? constraint.FirstAttribute : attribute1.Value, (relation == null) ? constraint.Relation : relation.Value, object2 ?? constraint.SecondItem, (attribute2 == null) ? constraint.SecondAttribute : attribute2.Value, (multiplier == null) ? constraint.Multiplier : multiplier.Value, (constant == null) ? constraint.Constant : constant.Value)); }
protected override bool Validating() { if (_defaultColor == null) { var firstRelationship = _sourceBindingRelationships.FirstOrDefault(); if (firstRelationship.Value != null) { var firstView = firstRelationship.Value.FirstOrDefault(); if (firstView != null) { _defaultColor = firstView.Layer.BorderColor; _defaultWidth = firstView.Layer.BorderWidth; } } } if (_sourceBindingRelationships == null) return false; foreach (var textView in _sourceBindingRelationships.SelectMany(sourceBindingRelationship => sourceBindingRelationship.Value)) { textView.Layer.BorderColor = _defaultColor; textView.Layer.BorderWidth = _defaultWidth.GetValueOrDefault(); } return true; }
/// Returns size for item considering number of rows and scroll direction, if preferredWidthOrHeight is nil, square size is returned public CGSize SizeForItem(int numberOfItemsInRow, nfloat?preferredWidthOrHeight, UICollectionView collectionView, UICollectionViewScrollDirection scrollDirection) { switch (scrollDirection) { case UICollectionViewScrollDirection.Horizontal: var itemHeight = collectionView.Frame.Height; itemHeight -= collectionView.ContentInset.Top + collectionView.ContentInset.Bottom; itemHeight -= (numberOfItemsInRow - 1) * Configuration.InterItemSpacing; itemHeight /= numberOfItemsInRow; return(new CGSize(preferredWidthOrHeight ?? itemHeight, itemHeight)); case UICollectionViewScrollDirection.Vertical: var itemWidth = collectionView.Frame.Width; itemWidth -= collectionView.ContentInset.Left + collectionView.ContentInset.Right; itemWidth -= (numberOfItemsInRow - 1) * Configuration.InterItemSpacing; itemWidth /= numberOfItemsInRow; return(new CGSize(itemWidth, preferredWidthOrHeight ?? itemWidth)); default: throw new ArgumentException("Should be invoked only with UICollectionViewScrollDirection"); } }
public static nfloat GetValueOrDefault(this nfloat?value, nfloat defaultValue) => null == value ? defaultValue : value.Value;
public static nfloat GetValueOrDefault(this nfloat?value) => value.GetValueOrDefault(0);