uislider – Sprite Kit iOS7 – 添加滑块

前端之家收集整理的这篇文章主要介绍了uislider – Sprite Kit iOS7 – 添加滑块前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我以为你可以在精灵套件应用程序中添加UIKit滑块/或按钮.

但无法弄清楚如何做到这一点,以编程方式创建滑块的代码

if (self.view) {
    CGRect frame = CGRectMake(0.0,0.0,200.0,300);
    UiSlider *slider = [[UiSlider alloc] initWithFrame:frame];
    //[slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
    [slider setBackgroundColor:[UIColor clearColor]];
    slider.minimumValue = 0.0;
    slider.maximumValue = 50.0;
    slider.continuous = YES;
    [self.view addSubview:slider];
    NSLog(@"View is alive - look for slider...");
} 
else {
    NSLog(@"No View!!");
}

以上不起作用,视图的子视图数量保持不变

我假设我必须将它作为子项添加到我的图层(SKNode),但addChild方法不适用于UiSlider.它需要是一个SKNode本身.

我在这里的场景课中叫这个

-(id)initWithSize:(CGSize)size {    

    if (self = [super initWithSize:size]) {
         // thought putting here would work 
         // but self.view is nil
    }

    return self;
}

感谢评论,我可以让它显示 – 但我必须在viewController类中添加,就像这样

- (void)viewDidLoad
{
[super viewDidLoad];

// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
SKScene * scene = [XBLMyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];

if (self.view) {
    CGRect frame = CGRectMake(0.0,300);
    UiSlider *slider = [[UiSlider alloc] initWithFrame:frame];
    //[slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
    [slider setBackgroundColor:[UIColor clearColor]];
    slider.minimumValue = 0.0;
    slider.maximumValue = 50.0;
    slider.continuous = YES;
    NSLog(@"View is alive - look for slider...");
    [self.view addSubview:slider];
} else {
    NSLog(@"No View!!");
}
}

在实际的场景类中是否没有它去做….

谢谢

解决方法

经过一番修修补补

我的解决方案,感谢@ LearnCocos2D提示

我的场景类需要这个

- (void) didMoveToView:(SKView *)view
{
    [self addSlider];
}

然后调用您的方法添加滑块….等

原文链接:https://www.f2er.com/iOS/328694.html

猜你在找的iOS相关文章