I am creating a UIButton
inside a UIView
. If I apply a transition to the UIView
the myButton_TouchUpInside
touch event on the UIButton
stops firing. Can anyone advise? ( see edit )
( I am using Xamarin here )
UIView myView = new UIView()
{
BackgroundColor = UIColor.Black,
RestorationIdentifier = identifier,
UserInteractionEnabled = true,
ClipsToBounds = true
};
UIButton myButton = new UIButton()
{
BackgroundColor = UIColor.Red,
UserInteractionEnabled = true
};
myButton.TouchUpInside += myButton_TouchUpInside;
myButton.SizeToFit();
myButton.Frame = new CGRect(0, 10, myButton.Bounds.Width, myButton.Bounds.Height);
myView.AddSubview(myButton);
View.AddSubview(myView);
Click events fire at this point. If I add a transition they stop working after the transition has occurred, I presume they have been left behind in the transition:
var myNewFrame = new CGRect(0, 50, myButton.Frame.Width, myButton.Frame.Height);
UIView.Transition(myView, 0.5, UIViewAnimationOptions.CurveEaseIn, () => { myView.Frame = myNewFrame; }, null);
I have read that the Frame
of the UIButton
is the key here. I checked the Frame
after adding it to the UIView
and then again in the completed Action
in the UIView.Transition
(not shown in the code above) and it's size and position are exactly the same.
edit
It isn't the transition that's causing the issue, its the animation that follows (the UIView
slides then after X seconds it fades out). Directly following the transition is this code:
UIView.Animate(0.25, 10, UIViewAnimationOptions.CurveEaseInOut, () => { myView.Alpha = 0; }, () => { myView.RemoveFromSuperview(); });
If I remove this, it works.
OK, rather than using the inbuilt delay property I wrapped it in an async method as so:
UIView.Transition(myView, 0.5, UIViewAnimationOptions.CurveEaseIn, () => { myView.Frame = myNewFrame; }, ()=> {FadeOut(duration)});
private async FadeOut(int duration){
await Task.Delay(duration * 1000);
UIView.Animate(0.25, 0, UIViewAnimationOptions.CurveEaseInOut, () => { myView.Alpha = 0; }, () => { myView.RemoveFromSuperview(); });
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.