Reputation: 767
I placed resumeLayer and PauseLayer method definitions within the @interface and @end block in h file.
@interface MainViewController : UIViewController
@property (nonatomic, retain) UIToolbar *toolbar;
@property (strong)AVAudioPlayer *audioPlayer;
@property (nonatomic, retain) NSTimer * timer;
- (void)resumeLayer:(CALayer *)layer;
- (void)pauseLayer:(CALayer *)layer;
@end
methods in m file
-(void)pauseLayer:(CALayer*)layer
{
CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
layer.speed = 0.0;
layer.timeOffset = pausedTime;
}
-(void)resumeLayer:(CALayer*)layer
{
CFTimeInterval pausedTime = [layer timeOffset];
layer.speed = 1.0;
layer.timeOffset = 0.0;
layer.beginTime = 0.0;
CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
layer.beginTime = timeSincePause;
}
Now want to call resumeLayer and PauseLayer method in PlayPauseAction method
-(void)playpauseAction:(id)sender {
if([audioPlayer isPlaying])
{
[sender setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateSelected];
[audioPlayer pause];
[self pauseTimer];
[self pauseLayer: CALayer];
}
else
{
[sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
[audioPlayer play];
[self resumeTimer];
if(isFirstTime == YES)
{
self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
target:self
selector:@selector(displayviewsAction:)
userInfo:nil
repeats:NO];
isFirstTime = NO;
}
}
}
Now when i call
[self PauseLayer:CALayer];
&
[self resumeLayer:CALayer];
gets message in red that unexpected interface name CALayer expected expression
.
Anyone can please tell how to call PauseLayer
and resumeLayer
method in playpauseAction
method.
Thanks for help.
Upvotes: 0
Views: 258
Reputation: 3398
This line does not make sense:
[self pauseLayer:CALayer];
because CALayer is a class. The compiler expects you to send in an object of type CALayer. You need to do something like:
//Get a reference to your UIImageView somehow
UIImageView *myImageView = [yourOtherClass getTheImageView];
[self pauseLayer:myImageView.layer]; // Pause the CALayer of the UIImageView
To explain why, compare with this code, lets say you have a method like this one to add a number from an NSNumber to an int "totalValue" that is stored inside a class:
/** Adds the number to totalValue **/
-(int)addNumber:(NSNumber)number {
totalValue = totalValue + [number intValue];
return totalValue;
}
The correct way to call this method would be for example:
// Store the value 10 into an NSNumber
NSNumber *numberToAdd = [NSNumber numberWithInt:10];
[self addNumber:numberToAdd]; // Add number 10 to totalValue
But this is what you are trying to do:
[self addNumber:NSNumber]; // WRONG, 'NSNumber' is not a value!
The compiler complains because CALayer is not a value, just like NSNumber is not a value. You can not do an operation like 10 + NSNumber. The code above wants an object, an instance of the class NSNumber, not a reference to the NSNumber class itself.
Upvotes: 1
Reputation: 5310
you need to put an instant not a class when you can your methods ..
so instead of calling it like this
[self PauseLayer:CALayer];
do something like
[self PauseLayer:(UIButton*)sender.layer];
Upvotes: 1
Reputation: 116
Try changing the P on -(void)pauseLayer:(CALayer*)layer {
to uppercase or the way around.
Upvotes: 0