【发布时间】:2013-10-11 05:55:06
【问题描述】:
我设置了一个 .h、.m 页面来为一些 UIImageView 对象设置动画,但无法让它们设置动画。没有收到任何警告、错误。
你能告诉我有什么问题吗? TIA
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *predictionLabel;
@property (strong, nonatomic) NSArray *predictionArray;
@property (strong, nonatomic) UIImageView *imageView;
- (void) makePrediction;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize predictionArray;
@synthesize imageView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImage *image = [UIImage imageNamed:@"background_s4.png"];
self.imageView = [[UIImageView alloc]initWithImage:image];
[self.view insertSubview:self.imageView atIndex:0];
self.imageView.animationImages = [[NSArray alloc]initWithObjects:[UIImage imageNamed:@"cball00001.png"],
[UIImage imageNamed:@"cball00002.png"],
[UIImage imageNamed:@"cball00003.png"],
[UIImage imageNamed:@"cball00004.png"],
[UIImage imageNamed:@"cball00005.png"],
[UIImage imageNamed:@"cball00006.png"],
[UIImage imageNamed:@"cball00007.png"],
[UIImage imageNamed:@"cball00008.png"],
[UIImage imageNamed:@"cball00009.png"],
[UIImage imageNamed:@"cball00010.png"],
[UIImage imageNamed:@"cball00011.png"],
[UIImage imageNamed:@"cball00012.png"],
[UIImage imageNamed:@"cball00013.png"],
[UIImage imageNamed:@"cball00014.png"],
[UIImage imageNamed:@"cball00015.png"],
[UIImage imageNamed:@"cball00016.png"],
[UIImage imageNamed:@"cball00017.png"],
[UIImage imageNamed:@"cball00018.png"],
[UIImage imageNamed:@"cball00019.png"],
[UIImage imageNamed:@"cball00020.png"],
[UIImage imageNamed:@"cball00021.png"],
[UIImage imageNamed:@"cball00022.png"],
[UIImage imageNamed:@"cball00023.png"],
[UIImage imageNamed:@"cball00024.png"], nil];
self.imageView.animationDuration = 1.0;
self.imageView.animationRepeatCount = 1;
self.predictionArray = [[NSArray alloc]initWithObjects:@"It is certain",
@"All signs are YES",
@"The stars are not aligned",
@"My reply is no",
@"It is doubtful",
@"Better not tell you now",
@"Concentrate and ask again",
@"Unable to answer now", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) makePrediction
{
NSUInteger index = arc4random_uniform(self.predictionArray.count);
self.predictionLabel.text = [self.predictionArray objectAtIndex:index];
[self.imageView startAnimating];
}
- (BOOL) canBecomeFirstResponder
{
return YES;
}
- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
self.predictionLabel.text = @"";
}
- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion == UIEventSubtypeMotionShake){
[self makePrediction];
}
}
- (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
NSLog(@"motion cancelled");
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
self.predictionLabel.text = @"";
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self makePrediction];
}
@end
【问题讨论】:
-
您确定 - (void) makePrediction 将在您运行代码时被调用吗?
-
在设置动画图片后尝试启动动画并检查它是否工作??
-
是的,就是调用predictionArray来保存随机引号。
-
"尝试在设置动画图像后立即启动动画并检查其是否有效??" 抱歉,无效。
标签: ios objective-c uiimageview