【问题标题】:Animate image out of view动画图像不可见
【发布时间】:2012-10-03 13:57:52
【问题描述】:

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

在 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)];

【问题讨论】:

  • 有人叫过showHideView吗?
  • 是的,当我按下按钮时。 - (IBAction)onClick:(id)sender { [self showHideView]; }
  • iOS4+强烈推荐基于块的动画...
  • 该方法是否实际被调用,即您是否通过设置断点或进行一些日志记录来确认? 2) 如果 animateLogo 为 nil,您是否检查过该方法?
  • 是的,它被称为。在 animateLogo 上做了一个 NSLog,它是一个 UIImageView,所以它不是 nil。

标签: objective-c xcode animation sdk uiimageview


【解决方案1】:

问题已解决。我使用了一种不同的方法,即我为 UIView 而不是 UIImageView 设置动画。我现在的工作就像一个魅力。

【讨论】:

    猜你喜欢
    • 2013-06-06
    • 1970-01-01
    • 2023-02-07
    • 2019-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-09
    相关资源
    最近更新 更多