雖然工作的一個項目,我做了一個類我在另一個類實例沒什麼特別的,但如果我嘗試調用這個例子中,我得到這個方法:廣東話調用方法
終止,由於應用程序未捕獲的異常 'NSInvalidArgumentException',原因是:「 - [CALayer的動畫]:無法識別的選擇發送到實例
這裏是類.H:
#import <QuartzCore/QuartzCore.h>
@interface SFStripe : CALayer {
NSTimer *animation;
}
- (id)initWithXPosition:(NSInteger)positionX yPosition:(NSInteger)positionY;
- (id)initEndedWithXPosition:(NSInteger)positionX yPosition:(NSInteger)positionY;
- (void)animate;
- (void)reduceSize;
- (void)logSomething;
@property NSTimer *animation;
@end
這裏的.M:
#import "SFStripe.h"
@implementation SFStripe
@synthesize animation;
- (id)initWithXPosition:(NSInteger)positionX yPosition:(NSInteger)positionY {
self = [CALayer layer];
self.backgroundColor = [UIColor blackColor].CGColor;
self.frame = CGRectMake(positionX, positionY, 5, 20);
self.cornerRadius = 5;
return self;
}
- (id)initEndedWithXPosition:(NSInteger)positionX yPosition:(NSInteger)positionY {
self = [CALayer layer];
self.backgroundColor = [UIColor grayColor].CGColor;
self.frame = CGRectMake(positionX, (positionY + 7.5), 5, 5);
self.cornerRadius = 2;
self.delegate = self;
return self;
}
- (void) logSomething {
NSLog(@"It did work!");
}
- (void)reduceSize {
if (self.frame.size.width > 0 && self.frame.size.height >= 5) {
self.frame = CGRectMake(self.frame.origin.x, (self.frame.origin.y - 0.5), self.frame.size.width, (self.frame.size.height - 0.5));
[self setNeedsDisplay];
NSLog(@"Width: %d", (int)self.frame.size.width);
NSLog(@"Height: %d", (int)self.frame.size.height);
} else {
self.backgroundColor = [UIColor grayColor].CGColor;
self.frame = CGRectMake(self.frame.origin.x, (self.frame.origin.y + 7.5), 5, 5);
[animation invalidate];
}
}
- (void)animate {
animation = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(reduceSize) userInfo:nil repeats:YES];
}
@end
我進口該類到一個新的項目只是爲了看看它是否在那裏工作,但得到了同樣的錯誤。這裏是我如何調用的類的實例的方法之一(我得到了所有的方法,同樣的錯誤)
在mainview.h(清潔工程):
#import <UIKit/UIKit.h>
#import "SFStripe.h"
#import <QuartzCore/QuartzCore.h>
@interface STViewController : UIViewController {
SFStripe *stripe;
}
- (IBAction)animate:(id)sender;
@end
我創建的實例,並在的.mi讓動作調用該實例的方法:
#import <QuartzCore/QuartzCore.h>
#import "STViewController.h"
#import "SFStripe.h"
@interface STViewController()
@end
@implementation STViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
stripe = [[SFStripe alloc] initWithXPosition:30 yPosition:30];
[self.view.layer addSublayer:stripe];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)animate:(id)sender {
[stripe animate];
}
@end
對不起,所有的代碼,但我不能找到這個問題,幫助,希望有人能幫助我一個答案!
我做了方法「logSomething」只是爲了看看我的方法出了什麼問題,但得到相同的錯誤! –
嘗試合成「條紋」。此外,只需在'animate'方法 – user427969