Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.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
Objective c 在视图外设置图像动画_Objective C_Xcode_Animation_Sdk_Uiimageview - Fatal编程技术网

Objective c 在视图外设置图像动画

Objective c 在视图外设置图像动画,objective-c,xcode,animation,sdk,uiimageview,Objective C,Xcode,Animation,Sdk,Uiimageview,我需要一个按钮来触发以下操作。当点击时,它应该将我的徽标向上推出视图并将其移除。当它再次点击时,它应该做相反的事情。这意味着图像被创建并向下推回到视图中。我正在使用故事板来设置我的界面。我的问题是我无法触发动画。在下面发布我的代码: 在TableViewController.h中 @interface TableViewController : UITableViewController{ BOOL status; } @property (weak, nonatomic) IBO

我需要一个按钮来触发以下操作。当点击时,它应该将我的徽标向上推出视图并将其移除。当它再次点击时,它应该做相反的事情。这意味着图像被创建并向下推回到视图中。我正在使用故事板来设置我的界面。我的问题是我无法触发动画。在下面发布我的代码:

在TableViewController.h中

@interface TableViewController : UITableViewController{

    BOOL status;

}

@property (weak, nonatomic) IBOutlet UIImageView *animateLogo;
@property (weak, nonatomic) IBOutlet UIButton *button;

- (IBAction)onClick:(id)sender;
- (void)showHideView;

@end
在TableViewController.m中

@synthesize animateLogo, button;

- (void)viewDidLoad{

    [super viewDidLoad];

    status = YES;

}

- (IBAction)onClick:(id)sender{
[self showHideView];
}

if(status){

    [UIView
     animateWithDuration:1.5
     delay:0
     options:UIViewAnimationCurveEaseOut
     animations:^{
         [animateLogo setFrame:CGRectOffset([animateLogo frame], 0, -animateLogo.frame.size.height)];
     }
     completion:^(BOOL completed) {}
    ];

    status = NO;
    [button setTitle:@"Show" forState:UIControlStateNormal];

}
else{

    [UIView
     animateWithDuration:1.5
     delay:0
     options:UIViewAnimationCurveEaseOut
     animations:^{
         [animateLogo setFrame:CGRectOffset([animateLogo frame], 0, animateLogo.frame.size.height)];
     }
     completion:^(BOOL completed) {}
    ];

    status = YES;
    [button setTitle:@"Hide" forState:UIControlStateNormal];

}

}
编辑:

如果我以编程方式编写UIImageView,则动画可以正常工作。所以问题就出在故事板上。我更喜欢用故事板来处理这个问题,这样我可以更好地忽略布局

UIImage *test = [UIImage imageNamed:@"logo.png"];
    animateLogo = [[UIImageView alloc] initWithImage:test];
    [self.view addSubview:animateLogo];
    [animateLogo setFrame:CGRectOffset([animateLogo frame], 0, animateLogo.frame.size.height)];

问题解决了。我使用了一种不同的方法,将UIView而不是UIImageView设置为动画。我现在工作得很卖力。

问题解决了。我使用了一种不同的方法,将UIView而不是UIImageView设置为动画。我现在工作得很有魅力。

有没有给showHideView打过电话?是的,当我按下按钮时。-(iAction)onClick:(id)sender{[self showHideView];}在iOS4+中强烈建议使用基于块的动画…是否实际调用了该方法,即是否通过设置断点或进行一些日志记录来确认?2) 你有没有检查过animateLogo是否为零?是的,它被调用了。NSLog在animateLogo上了吗?它是UIImageView,所以不是零。
showHideView
是否调用过?是的,当我按下按钮时。-(iAction)onClick:(id)sender{[self showHideView];}在iOS4+中强烈建议使用基于块的动画…是否实际调用了该方法,即是否通过设置断点或进行一些日志记录来确认?2) 你有没有检查过animateLogo是否为零?是的,它被调用了。在animateLogo上做了一个NSLog,它是一个UIImageView,所以它不是零。