Exemplo n.º 1
0
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            window = new UIWindow(UIScreen.MainScreen.Bounds);

            // create and initialize a UICollectionViewFlowLayout
            layout = new UICollectionViewFlowLayout()
            {
                HeaderReferenceSize = new SizeF(UIScreen.MainScreen.Bounds.Width, 50),
                SectionInset        = new UIEdgeInsets(10, 5, 10, 5),

                MinimumInteritemSpacing = 5,
                MinimumLineSpacing      = 5,
                ItemSize = new System.Drawing.SizeF(100, 100)
            };

            // create a CollectionViewController (which is a UICollectionViewController) with a layout
            viewController = new CollectionViewController(layout);


            // toggle the layout in response to a swipe left
            swipeLeft = new UISwipeGestureRecognizer(g => {
                if (customLayout == null)
                {
                    // create and initialize a CustomLayout
                    customLayout = new CustomLayout(viewController.Speakers.Count)
                    {
                        ItemSize = new SizeF(100, 100)
                    };
                }

                if (viewController.CollectionView.CollectionViewLayout is UICollectionViewFlowLayout)
                {
                    // switch to a custom layout
                    viewController.CollectionView.SetCollectionViewLayout(customLayout, true);
                }
                else
                {
                    // invalidate the flow layout in case the orientation changed
                    layout.InvalidateLayout();

                    // switch to a flow layout
                    viewController.CollectionView.SetCollectionViewLayout(layout, true);

                    // scroll to the top
                    viewController.CollectionView.SetContentOffset(new PointF(0, 0), false);
                }
            })
            {
                Direction = UISwipeGestureRecognizerDirection.Left
            };

            // add the gesture recognizer to the UICollectionView
            viewController.CollectionView.AddGestureRecognizer(swipeLeft);


            window.RootViewController = viewController;
            window.MakeKeyAndVisible();

            return(true);
        }
Exemplo n.º 2
0
		// This method is invoked when the application has loaded and is ready to run. In this
		// method you should instantiate the window, load the UI into it and then make the window
		// visible.
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			window = new UIWindow (UIScreen.MainScreen.Bounds);

			// create and initialize a UICollectionViewFlowLayout
			layout = new UICollectionViewFlowLayout () {

				HeaderReferenceSize = new SizeF (UIScreen.MainScreen.Bounds.Width, 50),
				SectionInset = new UIEdgeInsets (10,5,10,5),

				MinimumInteritemSpacing = 5,
				MinimumLineSpacing = 5,
				ItemSize = new System.Drawing.SizeF (100, 100)
			};

			// create a CollectionViewController (which is a UICollectionViewController) with a layout
			viewController = new CollectionViewController (layout);

			//TODO: Step 4b: uncomment to implement a left swipe gesture to switch between Collection View Layouts

			// toggle the layout in response to a swipe left
			swipeLeft = new UISwipeGestureRecognizer (g => {

				if (customLayout == null) {

					// create and initialize a CustomLayout
					customLayout = new CustomLayout (viewController.Speakers.Count){
						ItemSize = new SizeF (100, 100)
					};
				}

				if (viewController.CollectionView.CollectionViewLayout is UICollectionViewFlowLayout) {

					// switch to a custom layout
					viewController.CollectionView.SetCollectionViewLayout (customLayout, true);
				} else {

					// invalidate the flow layout in case the orientation changed
					layout.InvalidateLayout();

					// switch to a flow layout
					viewController.CollectionView.SetCollectionViewLayout (layout, true);

					// scroll to the top
					viewController.CollectionView.SetContentOffset(new PointF(0,0), false);
				}
			}){
				Direction = UISwipeGestureRecognizerDirection.Left
			};
			// add the gesture recognizer to the UICollectionView
			viewController.CollectionView.AddGestureRecognizer (swipeLeft);


			window.RootViewController = viewController;
			window.MakeKeyAndVisible ();

			return true;
		}
Exemplo n.º 3
0
        /// <summary>
        /// Updates the padding for when we center the content in the gridview
        /// </summary>
        void UpdatePadding()
        {
            if (Element == null || (ICollection)Element.ItemsSource == null)
            {
                return;
            }
            var numberOfItems = ((ICollection)Element.ItemsSource).Count;
            UICollectionViewFlowLayout flowLayout = _gridCollectionView != null ? (UICollectionViewFlowLayout)_gridCollectionView.CollectionViewLayout : null;

            if (flowLayout != null)
            {
                if (Element.IsContentCentered && numberOfItems > 0 && _gridCollectionView.Frame.Width > 0)
                {
                    flowLayout.InvalidateLayout();
                    float width = (float)_gridCollectionView.Frame.Width - 2;
                    int   numberOfItemsThatFit = (int)Math.Floor(width / (_gridCollectionView.ItemSize.Width));
                    int   numberOfItemsToUse   = Element.CenterAsFilledRow ? numberOfItemsThatFit : (int)Math.Min(numberOfItemsThatFit, numberOfItems);
                    if (Element.MaxItemsPerRow != -1)
                    {
                        numberOfItemsToUse = Element.MaxItemsPerRow;
                    }
                    var remainingWidth = width - (numberOfItemsToUse * (_gridCollectionView.ItemSize.Width));
                    var padding        = remainingWidth / (numberOfItemsToUse + 1);

                    Console.WriteLine(" width {0} items using {1} padding {2} iwdith {3} ", _gridCollectionView.Frame.Width, numberOfItemsToUse, padding, _gridCollectionView.ItemSize.Width);
                    _gridCollectionView.ColumnSpacing = padding;
                    _edgeInsets = new UIEdgeInsets((float)Element.ContentPaddingTop, (float)padding, (float)Element.ContentPaddingBottom, (float)padding);
                    Console.WriteLine("final insets " + _edgeInsets);
                    _gridCollectionView.ContentInset = _edgeInsets;
                }
                flowLayout.SectionInset = new UIEdgeInsets((float)Element.SectionPaddingTop, 0, (float)Element.SectionPaddingBottom, 0);
                if (_gridCollectionView.Frame.Width > 0 && _gridCollectionView.Frame.Height > 0)
                {
                    IsPaddingInvalid = false;
                }
            }
        }