public static void SetAppValue(string key, object value, NSString applicationId) { if (key == null) { throw new ArgumentNullException("key"); } else if (applicationId == null) { throw new ArgumentNullException("applicationId"); } using (var cfKey = new CFString(key)) { if (value == null) { CFPreferencesSetAppValue(cfKey.Handle, IntPtr.Zero, applicationId.Handle); } else if (value is string) { using (var valueStr = new CFString((string)value)) { CFPreferencesSetAppValue(cfKey.Handle, valueStr.Handle, applicationId.Handle); } return; } else if (value is NSString || value is CFString || value is NSData || value is CFData || value is NSArray || value is CFArray || value is NSDictionary || value is CFDictionary || value is NSNumber || value is CFBoolean) { CFPreferencesSetAppValue(cfKey.Handle, ((INativeObject)value).Handle, applicationId.Handle); return; } var nsnumber = NSNumber.FromObject(value); if (nsnumber != null) { using (nsnumber) { CFPreferencesSetAppValue(cfKey.Handle, nsnumber.Handle, applicationId.Handle); } return; } throw new ArgumentException("unsupported type: " + value.GetType(), "value"); } }
// sets up the scrolling in the correct direction // utilizes CSDisplayLink, a timer synchronized to the display refresh rate, to execute the smooth automated scrolling private void SetupScrollTimerInDirection(ScrollingDirection direction) { if (DisplayLink != null && !DisplayLink.Paused) { var userInfo = userInfos[DisplayLink]; var scrollingDirection = userInfo[ScrollingDirectionKey]; var number = (NSNumber)NSNumber.FromObject(scrollingDirection); ScrollingDirection oldDirection = (ScrollingDirection)number.Int32Value; if (direction == oldDirection) { return; } } InvalidatesScrollTimer(); DisplayLink = CADisplayLink.Create(HandleScroll); userInfos.Add(DisplayLink, NSDictionary.FromObjectAndKey(NSNumber.FromInt32((int)direction), new NSString(ScrollingDirectionKey))); DisplayLink.AddToRunLoop(NSRunLoop.Main, NSRunLoop.NSRunLoopCommonModes); }
/// <summary> /// Initializes a new instance of the <see cref="JZMultiChoice.JZMultiChoicesCircleButton"/> class. /// </summary> /// <param name="point">Center Point.</param> /// <param name="icon">Center Icon</param> /// <param name="sRadius">Small radius.</param> /// <param name="bRadius">Big radius.</param> /// <param name="mMenuItems">Choice items</param> /// <param name="isParallex">If set to <c>true</c> is parallex.</param> /// <param name="parallex">Parallex amount</param> /// <param name="vc">ViewContoller.</param> public JZMultiChoicesCircleButton(CGPoint point, UIImage icon , float sRadius, float bRadius, ChoiceItemCollection mMenuItems, bool isParallex , float parallex, UIViewController vc) : this(UIScreen.MainScreen.Bounds) { this.SmallRadius = sRadius; this.BigRadius = bRadius; this.isTouchDown = false; this.CenterPoint = point; this.IconImage = icon; this.ParallexParameter = parallex; this.Parallex = isParallex; this.ResponderUIVC = vc; BackgroundView = new UIView(new CGRect(point.X - sRadius, point.Y - sRadius, sRadius * 2, sRadius * 2)); BackgroundView.BackgroundColor = new UIColor(0f, 0f, 0f, 0.7f); BackgroundView.Layer.CornerRadius = sRadius; this.Add(BackgroundView); SmallButton = new UIButton(new CGRect(point.X - sRadius, point.Y - sRadius, sRadius * 2, sRadius * 2)); SmallButton.Layer.CornerRadius = sRadius; SmallButton.Layer.BackgroundColor = UIColor.FromRGBA(252.0f / 255.0f, 81.0f / 255.0f, 106.0f / 255.0f, 1.0f).CGColor; SmallButton.Layer.ShadowColor = UIColor.Black.CGColor; SmallButton.Layer.ShadowOffset = new CGSize(0.0f, 6.0f); SmallButton.Layer.ShadowOpacity = 0.3f; SmallButton.Layer.ShadowRadius = 4.0f; SmallButton.Layer.ZPosition = bRadius; SmallButton.SetImage(IconImage, UIControlState.Normal); SmallButton.AddTarget(TouchDown, UIControlEvent.TouchDown); SmallButton.AddTarget(this, new Selector("TouchDrag:withEvent:"), UIControlEvent.TouchDragInside); SmallButton.AddTarget(this, new Selector("TouchDrag:withEvent:"), UIControlEvent.TouchDragOutside); SmallButton.AddTarget(this, new Selector("TouchUpInside:withEvent:"), UIControlEvent.TouchUpInside); SmallButton.AddTarget(TouchUpOutside, UIControlEvent.TouchUpOutside); this.Add(SmallButton); label = new CATextLayer(); label.FontSize = 9.0f; label.String = @"Choose:"; label.FontSize = 40; label.SetFont(@"ArialMT"); label.AlignmentMode = CATextLayer.AlignmentCenter; label.ForegroundColor = UIColor.FromWhiteAlpha(1.0f, 0.0f).CGColor; label.Frame = new CGRect(-SmallRadius * 3, -52, SmallRadius * 8, 100); var UnScaleFactor = SmallRadius / BigRadius; label.Transform = CATransform3D.MakeScale(UnScaleFactor, UnScaleFactor, 1.0f); SmallButton.Layer.AddSublayer(label); var TransformPara = BigRadius / SmallRadius; var MultiChoiceRadius = (BigRadius + SmallRadius) / 8 / TransformPara; this.mItems = mMenuItems; IconArray = new List <UIImageView> (); var number = mMenuItems.Count; foreach (var aItem in this.mItems) { var i = mItems.IndexOf(aItem); var XOffest = 4 * MultiChoiceRadius * Math.Cos(2 * Math.PI * i / number); var YOffest = 4 * MultiChoiceRadius * Math.Sin(2 * Math.PI * i / number); var IconImageView = new UIImageView(new CGRect(sRadius + XOffest - MultiChoiceRadius, sRadius + YOffest - MultiChoiceRadius, MultiChoiceRadius * 2, MultiChoiceRadius * 2)); IconImageView.Image = aItem.Icon; IconImageView.Alpha = 0.0f; IconImageView.Hidden = true; SmallButton.Add(IconImageView); SmallButton.BringSubviewToFront(IconImageView); IconImageView.Layer.ContentsScale = UIScreen.MainScreen.Scale * BigRadius / SmallRadius; IconArray.Add(IconImageView); } var UnFullFactor = SmallRadius / this.Frame.Size.Height; CallbackIcon = new UIImageView(new CGRect((SmallButton.Frame.Size.Width - BigRadius) / 2, (SmallButton.Frame.Size.Height - BigRadius) / 2, BigRadius, BigRadius)); CallbackIcon.Layer.Transform = CATransform3D.MakeScale(UnFullFactor, UnFullFactor, 1.0f); CallbackIcon.Image = UIImage.FromBundle("CallbackSuccess"); CallbackIcon.Alpha = 0.0f; SmallButton.Add(CallbackIcon); CallbackMessage = new UILabel(); CallbackMessage.Text = @""; CallbackMessage.Alpha = 0.0f; CallbackMessage.Font = UIFont.SystemFontOfSize(20.0f); CallbackMessage.Layer.Transform = CATransform3D.MakeScale(UnFullFactor, UnFullFactor, 1.0f); CallbackMessage.TextColor = UIColor.White; //[UIColor whiteColor]; CallbackMessage.TextAlignment = UITextAlignment.Center; CallbackMessage.Frame = new CGRect((SmallButton.Frame.Size.Width - SmallRadius / 2) / 2, (SmallButton.Frame.Size.Height - SmallRadius / 4) / 2 + 6, SmallRadius / 2, SmallRadius / 4); SmallButton.Add(CallbackMessage); // FullPara = this.Frame.Size.Height / SmallRadius; var thning = SmallButton.Layer.ValueForKey(new NSString(@"transform.scale")); if (thning != null) { var val = (NSNumber)NSNumber.FromObject(thning); MidiumPara = val.DoubleValue; } else { MidiumPara = 1.0f; } SmallPara = 1.0f; }
// actual scrolling logic that gets called by the CADisplayInfo timer // only matters if we have an active scroll animation command public void HandleScroll() { if (DisplayLink == null) { return; } var userInfo = userInfos[DisplayLink]; var scrollingDirection = userInfo[ScrollingDirectionKey]; var number = (NSNumber)NSNumber.FromObject(scrollingDirection); ScrollingDirection direction = (ScrollingDirection)(number.Int32Value); if (direction == ScrollingDirection.ScrollingDirectionUnknown) { return; } var frameSize = CollectionView.Bounds.Size; var contentSize = CollectionView.ContentSize; var contentOffset = CollectionView.ContentOffset; var distance = (float)Math.Round(ScrollingSpeed / LX_FRAMES_PER_SECOND); var translation = new PointF(); switch (direction) { case ScrollingDirection.ScrollingDirectionUp: distance = -distance; var minY = 0.0f; if ((contentOffset.Y + distance) <= minY) { distance = -contentOffset.Y; } translation = new PointF(0.0f, distance); break; case ScrollingDirection.ScrollingDirectionDown: float maxY = Math.Max(contentSize.Height, frameSize.Height) - frameSize.Height; if ((contentOffset.Y + distance) >= maxY) { distance = maxY - contentOffset.Y; } translation = new PointF(0.0f, distance); break; case ScrollingDirection.ScrollingDirectionLeft: distance = -distance; float minX = 0.0f; if ((contentOffset.X + distance) <= minX) { distance = -contentOffset.X; } translation = new PointF(distance, 0.0f); break; case ScrollingDirection.ScrollingDirectionRight: float maxX = Math.Max(contentSize.Width, frameSize.Width) - frameSize.Width; if ((contentOffset.X + distance) >= maxX) { distance = maxX - contentOffset.X; } translation = new PointF(distance, 0.0f); break; default: break; } CurrentViewCenter = AddPoints(CurrentViewCenter, translation); if (CurrentView != null) { CurrentView.Center = AddPoints(CurrentViewCenter, PanTranslationInCollectionView); } CollectionView.ContentOffset = AddPoints(contentOffset, translation); }