【问题标题】:Reference of ImageView.layer object from one class to anotherImageView.layer 对象从一个类到另一个类的引用
【发布时间】:2012-06-22 13:48:14
【问题描述】:

ImageView 定义在名为 Third 的类中

- (void)viewDidLoad
{
// Displays UIImageView
UIImageView* ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 300, 235)];
self.view.backgroundColor = [UIColor brownColor];
// load all the frames of our animation
ImageView.animationImages = [NSArray arrayWithObjects:    
                         [UIImage imageNamed:@"3a.png"],
                         [UIImage imageNamed:@"3b.png"],
                         nil];
// all frames will execute in 24 seconds
ImageView.animationDuration = 24;
// start animating
[ImageView startAnimating];
 ImageView.layer.borderWidth = 2;
 ImageView.layer.borderColor = [[UIColor whiteColor]CGColor];    
 [ImageView.layer setMasksToBounds:YES];
 [ImageView.layer setCornerRadius:15.0f];
 [self.view addSubview:ImageView]; }

我怎样才能从这个第三类获取这个图像 view.layer 到另一个类的引用。

基本上我想为图像视图动画使用暂停层和恢复层。

使用

 [self pauseLayer:myImageView.layer]; // Pause the CALayer of the UIImageView

我应该参考一些类似的东西,但不知道如何在第三类的 viewdidload 中实现它,或者在第三类或另一个类中的哪里实现它。

 UIImageView *myImageView = [OtherClass getTheImageView];

所以寻求帮助。

谢谢。

【问题讨论】:

    标签: iphone animation calayer


    【解决方案1】:

    我解决了。在另一个类中,我正在加载第三类,代码如下

    -(void)Third {
    Third *thirdController = [[Third alloc] init];
    thirdController.view.frame = CGRectMake(0, 0, 320, 480);
    CATransition *transitionAnimation = [CATransition animation];
    [transitionAnimation setDuration:1];
    [transitionAnimation setType:kCATransitionReveal]; 
    [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
    [self.view.layer addAnimation:transitionAnimation forKey:kCATransitionReveal];
    [self.view addSubview:thirdController.view]; 
    [self.view addSubview:toolbar];
    [thirdController release];
    self.timer = [NSTimer scheduledTimerWithTimeInterval:23 target:self selector:@selector(Fourth) userInfo:nil repeats:NO];
    }
    

    我在这个加载代码中使用了相同的层。所以我把它作为参考。

    我用过

    [self pauseLayer:self.view.layer];
    

    用于暂停图像视图动画和恢复

    [self resumeLayer:self.view.layer];
    

    所以基本上在 playpauseAction 中,当我暂停和恢复计时器时,我正在暂停和恢复图像 view.layer 动画

     -(void)playpauseAction:(id)sender {
    
    if([audioPlayer isPlaying])
    {
        [sender setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateSelected];
        [audioPlayer pause];
        [self pauseTimer];
        [self pauseLayer:self.view.layer]; 
    }else{
        [sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
        [audioPlayer play];
        [self resumeTimer];
        [self resumeLayer:self.view.layer];
     if(isFirstTime == YES)
        {
            self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
                                                          target:self
                                                        selector:@selector(displayviewsAction:)
                                                        userInfo:nil
                                                         repeats:NO];
            isFirstTime  = NO;
        }
        } 
        }
    

    就这么简单,我浪费了两天时间来解决这个问题,但最后很高兴它像魅力一样工作没有问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-06
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-12
      • 1970-01-01
      相关资源
      最近更新 更多