Reputation: 1019
I have a class method where I want to perform this piece of code below. the problem is that in a class method you can't use something like self.view. so I'm a bit stuck here. I've found some stuff about using [self class] but I don't really understand how to use that in my piece of code.
for (UIView *view in [self.view subviews])
{
if([view isKindOfClass:[Circle class]]) {
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationCurveLinear animations:^{
view.alpha = 0;
view.frame = CGRectMake(self.view.frame.size.width/2-35, self.view.frame.size.height/2-35, 70, 70);
} completion:nil];
[view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.4];
} else {
//
}
}
UPDATE with more info
I have a Circle class. in that class I have this method
- (IBAction)playerTap:(id)sender {
NSString *numberString;
numberString = [NSString stringWithFormat:@"%i",indexNumber+1];
if (indexNumber < 14)
{
if ([label.text isEqualToString:numberString])
{
[UIView animateWithDuration:0.1 animations:^{
self.transform = CGAffineTransformMakeScale(1.2, 1.2);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.05 animations:^{
self.transform = CGAffineTransformIdentity;
self.alpha = 0.2;
} completion:nil];
}];
++indexNumber;
}
} else {
self.alpha = 0.2;
[NUMViewController gameHasEnded];
}
}
when the indexNumber (a static variable) has reached a certain amount I want a method in my NUMViewController Class to be performed. I.E. the "gameHasEnded" method.
that would be a method with the code at the beginning of this post. it will remove all other circle instances from the view.
a class method seemed the most logical for me because I'm not performing the method on the circle object but it affects all the objects in my other class.
Upvotes: 0
Views: 543
Reputation: 299633
It is not meaningful to have a class method that calls self.view
. The class does not have a view
, and there is no way to know which instance you mean. Why are you doing this in a class method? Move it to a the instance. If you have a shared singleton instance, than class methods can refer to it, but this is generally a bad idea and should be avoided if possible (since it ties your class to the singleton).
Upvotes: 3