我有一個Mac OSX Objective C項目,讓我感到困惑。 Xcode版本7.3,部署目標10.11。這個使用IB建立的項目除了顯示一個動畫正弦波外,並沒有像一個精靈那樣做。我想控制波浪的速度,並且爲了簡單,只需使用無線電矩陣選擇緩慢,中等和快速。有四個源代碼文件:爲什麼在方法didMoveToView中執行時自我改變的地址?
//AppDelegate.h
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (weak) IBOutlet NSMatrix *radioRef;
@end
//AppDelegate.m
#import "AppDelegate.h"
#import "SineWave.h"
@interface AppDelegate()
@property (weak) IBOutlet NSWindow *window;
@property (weak) IBOutlet SKView *skView;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
[self.radioRef selectCellWithTag:1];
SKScene *scene;
CGSize size = CGSizeMake(360, 216);
scene = [SineWave sceneWithSize:size];
scene.scaleMode = SKSceneScaleModeFill;
[self.skView presentScene:scene];
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
@end
//SineWave.h
#import <SpriteKit/SpriteKit.h>
@interface SineWave : SKScene
@property (weak) IBOutlet NSWindow *window;
@property (weak) IBOutlet SKView *skView;
@property NSArray *walkFrames;
- (IBAction)radioAction:(id)sender;
@property (weak) IBOutlet NSMatrix *radioRef;
- (void) didMoveToView : (SKView *) view;
- (NSArray *) animationFramesForImageNamePrefix: (NSString*) baseImageName frameCount: (NSInteger) count;
@end
//SineWave.m
#import "SineWave.h"
@implementation SineWave
- (void)didMoveToView:(SKView *)view {
CGFloat ThisSpeed = (CGFloat) self.radioRef.selectedCell.tag;
if (ThisSpeed < 1.0)
ThisSpeed = 1.0;
self.walkFrames = [self animationFramesForImageNamePrefix:@"SinWave" frameCount:45];
// Create the sprite with the initial frame.
SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithTexture:[self.walkFrames objectAtIndex:0]];
sprite.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
[self addChild:sprite];
SKAction *animateFramesAction = [SKAction animateWithTextures:self.walkFrames timePerFrame:0.05];
[sprite runAction:[SKAction repeatActionForever:animateFramesAction]];
sprite.speed = ThisSpeed;
}
- (NSArray *)animationFramesForImageNamePrefix: (NSString*) baseImageName frameCount: (NSInteger) count {
/* Loads a series of frames from files stored in the app bundle, returning them in an array. */
NSMutableArray *array = [NSMutableArray arrayWithCapacity:count];
for (int i = 1; i<= count; i++) {
NSString *imageName = [NSString stringWithFormat:@"%@%03d.png",baseImageName, i];
SKTexture *t = [SKTexture textureWithImageNamed:imageName];
[array addObject:t];
}
return array;
}
- (IBAction)radioAction:(id)sender {
CGSize size = CGSizeMake(360, 216);
SKScene *scene = [SineWave sceneWithSize:size];
scene.scaleMode = SKSceneScaleModeFill;
[self.skView presentScene:scene];
}
@end
這些是連接: sKView 無障礙:鏈接和標題=無 引用奧特萊斯:skView - >正弦波和代表 輔助參考文獻:鏈接和標題=無
無線電矩陣 網點:委託,格式化器,菜單,nextKeyView =無 發送的動作:動作 - >正弦波和radioAction 無障礙:鏈接和標題=無 引用缺貨讓:radioRef - >正弦波和代表 收稿操作:所有元素(performClick ... takeStringValueFrom)=無 輔助參考文獻:鏈接和標題=無
奧特萊斯(類正弦波)對象:無線電參考 skView:Sk的查看 窗口:窗口 引用奧特萊斯:無 接收操作:radioAction - >收音機參考
構建和執行精靈作品和顯示的代碼是跨視圖一個很好的正弦波滾動(skView在文件SineWave.h,第6行),但只能以一種速度。
無線電矩陣的標籤Slow = 1,Medium = 3和Fast = 6,希望產生1.0,3.0和6.0的ThisSpeed值。令我困惑的是radioRef的值爲零,而執行方法是didMoveToView。如何/應該在方法didMoveToView中獲得無線電矩陣的選定單元?