使用 NStimer 使用默认图像设置图像动画

Posted

技术标签:

【中文标题】使用 NStimer 使用默认图像设置图像动画【英文标题】:Using of NStimer to set image animation with default image 【发布时间】:2012-06-28 16:20:24 【问题描述】:

如何集成两张图片,其中一张作为默认图片,另一张在应用启动时作为动画图片。即使视图再次加载,动画图片也不应该再次出现。它应该只在应用启动时出现,如 default.png 图像。 .想法是获取两个默认图像..我该怎么做?..

这是我的代码...

@interface ViewController ()<UIActionSheetDelegate>

@property (nonatomic, assign) BOOL useButtons;

@end

@implementation ViewController

 @synthesize carousel,Chaintop;

#pragma mark -
#pragma mark View lifecycle

  - (void)viewDidLoad
 
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
carousel.type = iCarouselTypeInvertedWheel              ;

CGRect ChaintopFrame = Chaintop.frame;
ChaintopFrame.origin.y = self.view.bounds.size.height;    

[UIView animateWithDuration:3
                      delay:1.0
                    options: UIViewAnimationCurveEaseOut
                 animations:^
                  Chaintop.frame = ChaintopFrame;
                     //Chainbottom.frame = ChainbottomFrame;
                  
                 completion:^(BOOL finished)
                     NSLog(@"Done!");
                 ];
   [self.view addSubview: Chaintop];
   


 - (void)viewDidUnload
 
[super viewDidUnload];
 // Release any retained subviews of the main view.


 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);


    - (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
    
   return NUMBER_OF_ITEMS;
      

  - (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
  

   UIImage *buttonImage=[NSArray arrayWithObjects:[UIImage imageNamed:@"Cover_0.png"],
                      [UIImage imageNamed:@"Cover_1.png"],
                      [UIImage imageNamed:@"Cover_2.png"],
                      [UIImage imageNamed:@"Cover_3.png"],
                      [UIImage imageNamed:@"Cover_4.png"],
                      [UIImage imageNamed:@"Cover_5.png"],
                      [UIImage imageNamed:@"Cover_6.png"],
                      [UIImage imageNamed:@"Cover_7.png"],nil];

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 200.0f, 200.0f);

[button setImage:(UIImage*)[buttonImage objectAtIndex:index] forState:UIControlStateNormal]; 

[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
return button;



 

 -(void)dealloc
[Chaintop release];

 



 - (BOOL)carousel:(iCarousel *)_carousel shouldSelectItemAtIndex:(NSInteger)index
   
if (index == carousel.currentItemIndex)

    NSLog(@"Should select current item");

else

    NSLog(@"Should select item number %i", index);

return YES;
  

  - (void)carousel:(iCarousel *)_carousel didSelectItemAtIndex:(NSInteger)index
  
if (index == carousel.currentItemIndex)

    //note, this will only ever happen if useButtons == NO
    //otherwise the button intercepts the tap event
    NSLog(@"Did select current item");

else

    NSLog(@"Did select item number %i", index);

     
     @end

【问题讨论】:

我已经告诉过你,把它放在应用程序委托中,你启动屏幕或图像,然后为下一个图像设置计时器。 【参考方案1】:

在您的APP DELEGATE 中。 像这样的东西应该可以完成这项工作:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions     
    UIImageView *imageView = [[[UIImageView alloc] initWithFrame:self.window.bounds] autorelease];
    UIImage *image = [UIImage imageNamed:@"NAMEOFYOURSPLASHSCREEN.png"];
    imageView.image = image;
    [self.window addSubview:imageView];
    [self.window makeKeyAndVisible];
    [self performSelector:@selector(remove1stSplash:) withObject:imageView afterDelay:5];
    return YES;


- (void)remove1stSplash:(UIImageView *)1stView 
    UIImageView *imageView = ...
    [self.window addSubview:imageView];
    [self performSelector:@selector(remove2ndSplash:) withObject:imageView afterDelay:5];
    [1stView removeFromSuperView];


- (void)remove2ndSplash:(UIImageView *)2ndView 
    [self.window addSubview:.....
    [2ndView removeFromSuperView];

编辑:

示例项目的链接: Two Splash Screen display in iphone

【讨论】:

删除 Default.png 实现 this. 这只是一个 imageView,它会显示你的第一张图片,然后是另一张图片

以上是关于使用 NStimer 使用默认图像设置图像动画的主要内容,如果未能解决你的问题,请参考以下文章

重复 NSTimer 会导致在第一个动画上截断 animateWithDuration

应用程序在图像捕获中崩溃

使用两个图像为 iphone tableviewCell 背景图像设置动画

如何解决内存崩溃

如何在使用 CABasic 动画从屏幕顶部到底部设置动画时获取图像帧

在图像幻灯片和页面控件中添加 NSTimer 以自动移动图像