Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIImageView闪烁动画_Ios_Objective C_Uiimageview_Viewdidload - Fatal编程技术网

Ios UIImageView闪烁动画

Ios UIImageView闪烁动画,ios,objective-c,uiimageview,viewdidload,Ios,Objective C,Uiimageview,Viewdidload,我试图在viewDidLoad时使UIImageView闪烁。我不知道最好的方法是什么。我尝试过使用.hidden=YES和.hidden=NO循环,但这似乎是一种不好的方法。我需要一些适当的建议。使用UIImageView动画,您可以只放入一张空图像或一张空白图像: 享受如果您只想隐藏和显示,请使用NStimer 像这样的 在.h文件中添加此属性 @属性(非原子,强)NSTimer*计时器 - (void)onTimerEvent:(NSTimer*)timer { self.ima

我试图在
viewDidLoad
时使
UIImageView
闪烁。我不知道最好的方法是什么。我尝试过使用
.hidden=YES
.hidden=NO
循环,但这似乎是一种不好的方法。我需要一些适当的建议。

使用UIImageView动画,您可以只放入一张空图像或一张空白图像:


享受

如果您只想隐藏和显示,请使用NStimer 像这样的

在.h文件中添加此属性 @属性(非原子,强)NSTimer*计时器

- (void)onTimerEvent:(NSTimer*)timer
{
    self.imageView.hidden = !self.imageView.hidden;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(onTimerEvent:) userInfo:nil repeats:YES];
}
Swift

func onTimerEvent(timer: Timer) {
    self.imageView.isHidden = !self.imageView.isHidden
}

public override func viewDidLoad() {
    super.viewDidLoad()
    Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(onTimerEvent(timer:)), userInfo: nil, repeats: true)
}
但是UIImageView也可以为不同的图像设置动画 像这样的

self.iamgeView.animationImages = <arrayOfImages>
self.imageView.duration = <duration>
self.iamgeView.animationImages=
self.imageView.duration=

您可以使用UIImageView的alpha。下面是一个示例(只需在
viewDidLoad
中调用
startAnim
):

static NSInteger count=0;
静态NSInteger maxBlind=10;
-(无效)斯塔塔尼姆{
CGF持续时间=0.5f;
[UIView animateWithDuration:AnimanDuration
动画:^{
self.myImageView.alpha=0.f;
}完成:^(布尔完成){
[UIView animateWithDuration:AnimanDuration
动画:^{
self.myImageView.alpha=1.f;
}完成:^(布尔完成){
如果(计数<最大盲){
[自我启动];
计数++;
}
}];
}];
}
试试这个:

-(void)blink:(UIView*)view count:(int) count
{
    if(count == 0)
    {
        return;
    }

    [UIView animateWithDuration:0.2 animations:^{

        view.alpha = 0.0;

    } completion:^(BOOL finished){

        [UIView animateWithDuration:0.2 animations:^{

            view.alpha = 1.0;

        } completion:^(BOOL finished){

            [self blink:view count:count-1];

        }];


    }];
}
或者,如果您希望它永远闪烁,请尝试以下方法:

-(void)blinkForever:(UIView*)view
{
    [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionAutoreverse|UIViewAnimationOptionRepeat animations:^{

        view.alpha = 0.0;

    } completion:nil];
}

我尝试了此操作,但收到一条错误消息:在类型为“DemoViewController*”的对象上找不到属性“timer”。您需要在DemoViewController.hThanks brother中添加NStimer*timer作为属性,我很快会检查它。我还有一个问题在下面的链接:上面是好的,谢谢你,但遗漏了一行。您需要删除第二个完成块中的imageView,否则它将保持在原位,以遮挡淡入/淡出:}完成:^(BOOL finished){if(count-(void)blinkForever:(UIView*)view { [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionAutoreverse|UIViewAnimationOptionRepeat animations:^{ view.alpha = 0.0; } completion:nil]; }