我试图创建一个闪烁的BoxView。我创建了一个BlinkingBoxView,它扩展了BoxView并添加了一个名为" Blink"的布尔属性。所以我想要的是,每次Blink改变并且它的值是真的,我想开始闪烁动画,如果值为false则停止动画。
我需要在C#代码中执行此操作,还是只能像WPF一样使用XAML?
这是我的尝试...
public class BlinkingBoxView : BoxView
{
public BlinkingBoxView()
: base()
{
}
public static readonly BindableProperty BlinkProperty = BindableProperty.Create<BlinkingBoxView, bool>(w => w.Blink, default(bool), BindingMode.TwoWay);
public bool Blink
{
get { return (bool)GetValue(BlinkProperty); }
set
{
SetValue(BlinkProperty, value);
var blinkAnimation = new Animation(d => this.FadeTo(0, 750, Easing.Linear)).WithConcurrent(new Animation(d => this.FadeTo(1, 750, Easing.Linear)));
if (this.Blink)
this.Animate("Blink", blinkAnimation);
}
}
}
答案 0 :(得分:2)
您应该使用- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
tabBarController.delegate = self;
return YES;
}
- (void)tabBarController:(UITabBarController *)tabBarController
didSelectViewController:(UIViewController *)viewController
{
NSLog(@"Selected tab bar button!");
}
覆盖来捕获属性更改:
OnPropertyChanged
您可以在XAML中使用它,与其他任何public class BlinkingBoxView : BoxView
{
volatile bool isBlinking;
public static readonly BindableProperty BlinkProperty = BindableProperty.Create<BlinkingBoxView, bool>(w => w.Blink, default(bool), BindingMode.OneWay);
public bool Blink
{
get
{
return (bool)GetValue(BlinkProperty);
}
set
{
SetValue(BlinkProperty, value);
}
}
public static readonly BindableProperty BlinkDurationProperty = BindableProperty.Create<BlinkingBoxView, uint>(w => w.BlinkDuration, 500, BindingMode.OneWay);
public uint BlinkDuration
{
get
{
return (uint)GetValue(BlinkDurationProperty);
}
set
{
SetValue(BlinkDurationProperty, value);
}
}
protected override void OnPropertyChanged(string propertyName)
{
base.OnPropertyChanged(propertyName);
if (propertyName == BlinkProperty.PropertyName)
{
SetBlinking(Blink);
}
if (propertyName == BlinkDurationProperty.PropertyName)
{
if (isBlinking)
{
SetBlinking(false);
SetBlinking(Blink);
}
}
}
void SetBlinking(bool shouldBlink)
{
if (shouldBlink && !isBlinking)
{
isBlinking = true;
var blinkAnimation = new Animation(((d) => {
Opacity = d;
}), 0f, 1f, Easing.SinInOut);
this.Animate("BlinkingBoxViewBlink", blinkAnimation, length: BlinkDuration, repeat: () => isBlinking);
}
else if (!shouldBlink && isBlinking)
{
isBlinking = false;
}
}
}
一样。