【问题标题】:Xcode I want to pass a variable into the method [closed]Xcode我想将一个变量传递给方法[关闭]
【发布时间】:2012-09-09 22:00:13
【问题描述】:
-(void)end{
NSLog(@"End Called");

}    

UIImage *bPin = [UIImage imageNamed:@"BluePin.png"];
        UIImage *gPin = [UIImage imageNamed:@"GreenPin.png"];
        UIImage *rPin = [UIImage imageNamed:@"RedPin.png"];
        UIImage *yPin = [UIImage imageNamed:@"YellowPin.png"];
        UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,bPin.size.width,bPin.size.height)];
        image.animationImages = [NSArray arrayWithObjects:
                                 bPin,
                                 rPin,
                                 gPin,
                                 yPin,
                                 nil];

        image.animationRepeatCount = 0;
        image.animationDuration = 1.0;
        [image startAnimating];

        [image setFrame: CGRectMake(point.x-(image.bounds.size.width/2), point.y-(image.bounds.size.width/2), image.bounds.size.width, image.bounds.size.height)];
        [self.view addSubview: image];



        [UIView animateWithDuration:2.0 delay:1.0 options:UIViewAnimationOptionCurveLinear  animations:^{
            [image setAlpha:0.0];
        } completion:^(BOOL finished) {
            [image removeFromSuperview];

        }];

我想将图像发送到 void end 方法,但我该怎么做?我需要在那里结束它以便为某个图像设置动画......我该如何发送它?????

【问题讨论】:

  • 您没有从代码中的任何位置调用end,因此很难回答您的问题。

标签: iphone objective-c xcode methods


【解决方案1】:

我没有看到问题是什么(也没有看到这个问题与 Xcode 有什么关系),为什么不简单

- (void)end:(UIImage *)img
{
    // do stuff
}

然后这样称呼它

[self end:imageView.image];

?

【讨论】:

  • 我会在 void 端做东西,但我不知道如何将对象图像发送到 void 端????和[自我结束:imageView.image];没用
  • @userxxx 您没有“发送对象”。如果您甚至不知道如何使用参数调用方法,那么您可能应该阅读 Objective-C 教程而不是深入开发 iOS 应用程序... 我刚刚向您解释了如何做这一切……
【解决方案2】:

将您的结束方法更新为这样

- (void) end:(UIImageView *)imageToAnimate {
     NSLog(@"end called");
}

然后调用它:

[self end:image];

【讨论】:

  • 并调用该方法但不发送任何内容 [self end:nil]; ?我也需要用另一种方法调用它,但什么也不发送
  • 是的,如果您不想传递任何对象,可以发送nil
  • 好的,我如何将一些东西传递给 -(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ [self touchesCancelled:image];不工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-21
  • 2012-12-21
  • 2015-03-06
  • 1970-01-01
  • 2016-04-20
相关资源
最近更新 更多