I want translate this code
[UIView animateWithDuration:0.25
animations:^{
self.datePicker.alpha = 0.0f;
}
completion:^(BOOL finished){
self.datePicker.hidden = YES;
}
];
to Xamarin iOS:
UIView.Animate (0.25,
animation: () => {
this.datePicker.Alpha = 0.0f;
},
completion: (finished){
this.datePicker.Hidden = true;
}
);
The problem is in the completion
block. How do I use the bool finished
here?
I get
Unexpected Symbol
{
A completion handler in Swift is a function that calls back when a task completes. This is why it is also called a callback function. A callback function is passed as an argument into another function. When this function completes running a task, it executes the callback function.
A completion handler is nothing more than a simple block declaration passed as a parameter to a method that needs to make a callback at a later time.
In short : Completion handlers are a way of implementing callback functionality using blocks or closures. Blocks and Closures are chunks of code that can be passed around to methods or functions as if they were values (in other words "anonymous functions" which we can give names to and pass around). Save this answer.
The completion block should be used to notify interested objects that the work is complete or perform other tasks that might be related to, but not part of, the operation's actual task. A finished operation may finish either because it was cancelled or because it successfully completed its task.
It's basic lambda expression.
UIView.Animate (0.25,
animation: () => {
this.datePicker.Alpha = 0.0f;
},
completion: () => {
this.datePicker.Hidden = true;
}
);
Or since you have only one statement in your body, you can cut it down even further to
UIView.Animate (0.25,
animation: () => this.datePicker.Alpha = 0.0f,
completion: () => this.datePicker.Hidden = true
);
Use UIView.AnimateNotify() to get the delegate for the completion handler that uses the bool parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With