【发布时间】:2016-06-03 12:43:52
【问题描述】:
我在UIView 中创建了一个UIButton。如果我对UIView 应用过渡,UIButton 上的myButton_TouchUpInside 触摸事件将停止触发。任何人都可以建议吗? (查看编辑)
(我在这里使用 Xamarin)
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);
此时点击事件触发。如果我添加一个过渡,它们在过渡发生后停止工作,我认为它们在过渡中被抛在后面:
var myNewFrame = new CGRect(0, 50, myButton.Frame.Width, myButton.Frame.Height);
UIView.Transition(myView, 0.5, UIViewAnimationOptions.CurveEaseIn, () => { myView.Frame = myNewFrame; }, null);
我已经读到UIButton 的Frame 是这里的关键。在将Frame 添加到UIView 之后,我检查了Frame,然后再次在UIView.Transition 中完成了Action(上面的代码中未显示),它的大小和位置完全相同。
编辑
导致问题的不是过渡,而是随后的动画(UIView 滑动,然后在 X 秒后淡出)。直接在转换之后是这段代码:
UIView.Animate(0.25, 10, UIViewAnimationOptions.CurveEaseInOut, () => { myView.Alpha = 0; }, () => { myView.RemoveFromSuperview(); });
如果我删除它,它会起作用。
【问题讨论】:
标签: objective-c swift xamarin uibutton xamarin.ios