Reputation: 179
I am developing an iPad app in Xamarin and we have to provide orientation support.
In my scenario, I have to add multiple views in a scroll view which I am managing by enabling paging.
Now the issue is with orientation. While the device is rotated I have update the content size of scroll view.
In Xcode I am able to manage the thing using below function:
-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator: (id<UIViewControllerTransitionCoordinator>)coordinator
{
// before rotation
[coordinator animateAlongsideTransition:^(id _Nonnull context) {
// during rotation: update our image view's bounds and centre
} completion:^(id _Nonnull context) {
// after rotation
}];
}
So can anyone guide me how can I use this function in Xamarin too? I want to use the completion block.
Upvotes: 1
Views: 818
Reputation: 4127
In Xamarin.iOS most of the iOS SDK APIs are bound to similarly named methods in C#.
So for viewWillTransitionToSize
you would use the following in your view controller:
public override void ViewWillTransitionToSize(CoreGraphics.CGSize toSize, IUIViewControllerTransitionCoordinator coordinator)
{
coordinator.AnimateAlongsideTransition((IUIViewControllerTransitionCoordinatorContext obj) => {
// Define any animations you want to perform (equivilent to willRotateToInterfaceOrientation)
}, (IUIViewControllerTransitionCoordinatorContext obj) => {
// Completition executed after transistion finishes (equivilent to didRotateFromInterfaceOrientation)
});
base.ViewWillTransitionToSize(toSize, coordinator);
}
https://developer.xamarin.com/api/member/UIKit.UIViewController.ViewWillTransitionToSize/
Upvotes: 2