Search code examples
iosuiviewcore-animation

Sub Classing UIView Error


When I set an xib class to a sub class of UIView and then animateWithDuration on the UIView I get

No visible @interface for 'UIView' declares the selector
'animateWithDuration:delay:options:animations:completion:' 

The error pane shows it is an ARC issue

enter image description here

I am trying to run an animation on the UIView.

EDIT: The code causing error

 [sampleSourceView.view animateWithDuration:1
                                             delay:1.0
                                           options: UIViewAnimationCurveEaseOut
                                        animations:^{
                                            sampleSourceView.view.frame = sampleSourceFrame;
                                        } 
                                        completion:^(BOOL finished){
                                            NSLog(@"Done!");
                                        }];

        [self.view addSubview:sampleSourceView.view];

Solution

  • You are getting the error because you are trying to use a class method on an instance of UIView. Check out the method signature:

    + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
    

    The plus sign indicates it is a class method. An instance method would have a minus sign.

    Try this:

    [UIView animateWithDuration:1
                         delay:1.0
                       options: UIViewAnimationCurveEaseOut
                    animations:^{
                        sampleSourceView.view.frame = sampleSourceFrame;
                    } 
                    completion:^(BOOL finished){
                        NSLog(@"Done!");
                    }];