private void selectGoodScrollPoint(TimeSpan timeOfDay) { var frameHeight = CalendarCollectionView.Frame.Height - CalendarCollectionView.ContentInset.Top - CalendarCollectionView.ContentInset.Bottom; var hoursOnScreen = frameHeight / (CalendarCollectionView.ContentSize.Height / 24); var centeredHour = calculateCenteredHour(timeOfDay.TotalHours, hoursOnScreen); var offsetY = (centeredHour / 24) * CalendarCollectionView.ContentSize.Height - (frameHeight / 2); var scrollPointY = offsetY.Clamp(0, CalendarCollectionView.ContentSize.Height - frameHeight); var offset = new CGPoint(0, scrollPointY); CalendarCollectionView.SetContentOffset(offset, false); }
public override void ViewDidLoad() { base.ViewDidLoad(); settingsButton.SetImage(UIImage.FromBundle("icSettings"), UIControlState.Normal); ViewModel .ShouldShowOnboarding .FirstAsync() .Subscribe( shouldShowOnboarding => OnboardingView.Alpha = shouldShowOnboarding ? 1: 0) .DisposedBy(DisposeBag); this.Bind(ViewModel.ShouldShowOnboarding, OnboardingView.Rx().IsVisibleWithFade()); this.Bind(GetStartedButton.Rx().Tap(), ViewModel.GetStartedAction); var timeService = Mvx.Resolve <ITimeService>(); dataSource = new CalendarCollectionViewSource( CalendarCollectionView, ViewModel.Date, ViewModel.TimeOfDayFormat, ViewModel.CalendarItems); layout = new CalendarCollectionViewLayout(timeService, dataSource); editItemHelper = new CalendarCollectionViewEditItemHelper(CalendarCollectionView, dataSource, layout); createFromSpanHelper = new CalendarCollectionViewCreateFromSpanHelper(CalendarCollectionView, dataSource, layout); CalendarCollectionView.SetCollectionViewLayout(layout, false); CalendarCollectionView.Delegate = dataSource; CalendarCollectionView.DataSource = dataSource; CalendarCollectionView.ContentInset = new UIEdgeInsets(20, 0, 20, 0); this.Bind(dataSource.ItemTapped, ViewModel.OnItemTapped); this.Bind(settingsButton.Rx().Tap(), ViewModel.SelectCalendars); this.Bind(editItemHelper.EditCalendarItem, ViewModel.OnUpdateTimeEntry); this.Bind(ViewModel.SettingsAreVisible, settingsButton.Rx().IsVisible()); this.Bind(createFromSpanHelper.CreateFromSpan, ViewModel.OnDurationSelected); CalendarCollectionView.LayoutIfNeeded(); var currentTimeY = layout.FrameForCurrentTime().Y; var scrollPointY = currentTimeY - View.Frame.Height / 2; var currentTimePoint = new CGPoint(0, scrollPointY.Clamp(0, CalendarCollectionView.ContentSize.Height)); CalendarCollectionView.SetContentOffset(currentTimePoint, false); }
public void ScrollToTop() { CalendarCollectionView.SetContentOffset(CGPoint.Empty, true); }