小编OMG*_*POP的帖子

目标c无法定义宏

我有这个

#define sud [NSUserDefaults standardUserDefault]
Run Code Online (Sandbox Code Playgroud)

然后我用[sud integerForKey:key]

编译警告:

Class method '+standardUserDefault' not found (return type defaults to 'id')
Run Code Online (Sandbox Code Playgroud)

运行时错误:

+[NSUserDefaults standardUserDefault]: unrecognized selector sent to class 0x3c0bc850
Run Code Online (Sandbox Code Playgroud)

但我可以使用另一个没有任何警告:

#define man [Manager sharedManager]
Run Code Online (Sandbox Code Playgroud)

其中'man'是游戏经理(单身人士)来存储游戏得分等

iphone objective-c cocos2d-iphone ios

3
推荐指数
1
解决办法
142
查看次数

iOS Parse如何通过URL下载文件

我正在使用解析来聊聊我的应用程序.当我上传文件时,我会保留网址,并将网址发送给其他用户,然后用户可以通过此网址下载文件.

这是我上传文件的代码:

+ (void)uploadBlob:(NSData *)blob fileName:(NSString *)fileName type:(NSString *)type {
    if ([self private_checkCloudForbidden]) {
        return;
    }

    if (CHOSEN_SERVER_DATABASE == ServersQuickBlox) {
        if ([Format isThumbnailWithBlobFileName:fileName]) {
            type = @"image";
        }

        NSString *qbContentType = @"";
        if ([type isEqualToString:@"image"]) {
            qbContentType = @"image/jpg";
        }

        [QBContent TUploadFile:blob fileName:fileName contentType:qbContentType isPublic:YES delegate:[CloudDelegate sharedInstance]];


    }

    else if (CHOSEN_SERVER_DATABASE == ServersParse) {

        PFFile *file = [PFFile fileWithName:fileName data:blob];

        [file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            if (error){
                NSLog(@"Error: %@", [[error userInfo] objectForKey:@"error"]);
            } else {

                [CloudHandler didUploadBlobWithFileName:file.name blobID:file.url]; …
Run Code Online (Sandbox Code Playgroud)

database parsing backend ios parse-platform

3
推荐指数
1
解决办法
3238
查看次数

d3如何调整饼图的内半径

我需要将饼图动画制作成圆环图(或环形图)。这是我的代码:

  var arc = d3.svg.arc().outerRadius(radius-margin).innerRadius(0)
  var arc2 = d3.svg.arc().outerRadius(radius-margin).innerRadius(60)

  var path = pie_chart.selectAll('path')
    .data(pie(data))
    .enter()
    .append('path')
    .attr('d', arc)
    .attr('fill', function(d, i) {
      return color_scale(d.data.device)
    })
    .transition().attr('d', arc2)
Run Code Online (Sandbox Code Playgroud)

有时它有效,但有时却无效。我尝试将过渡应用于圆弧但不起作用。

 var arc2 = d3.svg.arc().outerRadius(radius-margin).innerRadius(0).transition().innerRadius(60)
Run Code Online (Sandbox Code Playgroud)

svg d3.js

3
推荐指数
1
解决办法
1602
查看次数

Swift 在十进制格式中失去精度

使用小数类型处理货币输入时,我遇到精度问题。问题出在格式化程序上。这是游乐场中最小的可重现代码:

let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.isLenient = true
formatter.maximumFractionDigits = 2
formatter.generatesDecimalNumbers = true

let text = "89806.9"
let decimal = formatter.number(from: text)?.decimalValue ?? .zero
let string = "\(decimal)"
print(string)
Run Code Online (Sandbox Code Playgroud)

它打印出来89806.89999999999而不是89806.9. 然而,大多数其他数字都很好(例如8980.9)。所以我不认为这是双精度与小数的问题。

编辑:

我需要使用格式化程序的原因是有时我需要处理货币格式输入:

let text = "$89,806.9"
let decimal = formatter.number(from: text)?.decimalValue ?? .zero
print("\(decimal)") // prints 89806.89999999999

let text2 = "$89,806.9"
let decimal2 = Decimal(string: text2)
print("\(decimal2)") // prints nil

Run Code Online (Sandbox Code Playgroud)

swift

3
推荐指数
1
解决办法
1189
查看次数

iOS 在模拟器上播放音频成功但在设备上失败

我使用录音机在文档目录中录制和创建文件,然后我使用音频播放器播放它。我可以在模拟器和设备上录制它,但我不能只在设备上播放。

请注意 1. 我不从文件播放声音,我从 NSData 播放(我将音乐存储到数据库中,然后检索它们以播放) 2. 它在模拟器上运行良好,但在设备上失败。

这是我播放音频的代码

- (void)playAudioWithData:(NSData *)data {

    [self stopPlayingAudio];
    [self stopRecordingAudio];


    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
    [audioSession setActive:YES error:nil];


    self.audioPlayer = [[AVAudioPlayer alloc] initWithData:data error:nil];

    [self.audioPlayer play];

}
Run Code Online (Sandbox Code Playgroud)

这是录制设置:

    NSDictionary *audioSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                   [NSNumber numberWithFloat:44100],AVSampleRateKey,
                                   [NSNumber numberWithInt: kAudioFormatLinearPCM],AVFormatIDKey,
                                   [NSNumber numberWithInt: 1],AVNumberOfChannelsKey,
                                   [NSNumber numberWithInt:AVAudioQualityMedium],AVEncoderAudioQualityKey,nil];
Run Code Online (Sandbox Code Playgroud)

audio cocoa-touch core-audio avfoundation ios

2
推荐指数
1
解决办法
839
查看次数

Kotlin减少2d列表的功能不起作用

我需要得到一个2d列表的总大小.这是我的实施:

    fun totalSize(parts: List<List<String>>): Int {
        return parts.reduce { total, next -> total + next.size }
    }
Run Code Online (Sandbox Code Playgroud)

我得到类型推断失败.必需的Int,Got List.但是next.size应该返回Int.

android kotlin

2
推荐指数
1
解决办法
323
查看次数

libGDX InputListener、InputProcessor、InputAdapter 有什么区别

我对 libGDX 的触摸处理有点困惑。我已经看到了这三种类型的用法。

输入处理器: http://www.gamefromscratch.com/post/2013/10/24/LibGDX-Tutorial-5-Handling-Input-Touch-and-gestures.aspx

public class InputDemo2 implements ApplicationListener, InputProcessor {
    @Override
    public void create() {        
        Gdx.input.setInputProcessor(this);
    }


    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    }
}
Run Code Online (Sandbox Code Playgroud)

InputListener这里: http://www.gamefromscratch.com/post/2013/11/27/LibGDX-Tutorial-9-Scene2D-Part-1.aspx

    public MyActor(){
        setBounds(actorX,actorY,texture.getWidth(),texture.getHeight());
        addListener(new InputListener(){
            public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
                ((MyActor)event.getTarget()).started = true;
                return true;
            }
        });
    }
    
Run Code Online (Sandbox Code Playgroud)

InputAdapter这里: LibGdx,如何处理触摸事件?

public class Prac1 extends ApplicationAdapter {
    @Override
    public void create () {
        Gdx.input.setInputProcessor(new InputAdapter(){ …
Run Code Online (Sandbox Code Playgroud)

libgdx

2
推荐指数
1
解决办法
2310
查看次数

CCRandom_0_1()生成相同的数字

我使用CCRandom_0_1()生成一个随机数,如"learn-iphone-and-ipad-with-cocos2d"一书所示,但似乎该函数生成相同的数字.

    int ran1 = ((int) (CCRANDOM_0_1() * 5)) + 1;
    int ran2 = ran1;
    while (ran2 == ran1) {
        ran2 = ((int) (CCRANDOM_0_1() * 5)) + 1;
    }
Run Code Online (Sandbox Code Playgroud)

这里是我想要从1到5生成2个不同整数的代码,但控制台始终是

2011-05-28 14:57:56.699 LetsSpotIt[2443:707] r1: 4.200939 r1: 1.971915
Run Code Online (Sandbox Code Playgroud)

无论如何我可以根据时间播种它(迷你秒),还是有其他功能可以使用?

请给我示例代码.我之前没有学过c或c ++.谢谢.

iphone random cocos2d-iphone ios

1
推荐指数
1
解决办法
5386
查看次数

mac app 主包资源权限与沙箱和权利

可能的重复:
Mac OS X:我应该在哪里存储作为捆绑交付的游戏的保存游戏?

我正在将我的 iOS 游戏迁移到 Mac。我用来存放高分的文件保存在xxx.app/Contents/Resources下。但是,当我启用沙箱和授权时,目录变得不可写。我也尝试过 xxx.app 和 xxx.app/Contents 也没有运气。那么我应该使用哪个目录或我应该添加哪个权利?

编辑我试过 ~/Library/Application Support/Your Game Name/ 并且它没有显示权限错误但无法保存游戏数据。在 user/my_name 下没有 Library,但在 unser/shared 下有一个。我需要添加任何权利吗?

编辑 2:请不要关闭这个问题。先前问题的答案对我不起作用。相反,这个问题的标记答案是正确的。

macos sandbox

1
推荐指数
1
解决办法
1009
查看次数

iOS使用我自己的图像后缀时图像尺寸错误

我使用iPhone的bg.png,iPhone视网膜和iPad的bg @ 2x,iPad视网膜的bg @ 4x.这是我写的代码:(在Helper.m中)

+ (UIImage *) imageNamed:(NSString *)name
{
    name = [name stringByReplacingOccurrencesOfString:@".png" withString:@""];
    UIImage *image;
    if (IS_IPAD) {
        if (IS_RETINA) {
            image = [UIImage imageNamed:[NSString stringWithFormat:@"%@@4x.png", name]];
            if (image) {
                return image;
            }
        }

        return [UIImage imageNamed:[NSString stringWithFormat:@"%@@2x.png", name]];
    }
    else {
        if (IS_RETINA) {
            image = [UIImage imageNamed:[NSString stringWithFormat:@"%@@2x.png", name]];
            if (image) {
                return image;
            }
        }
        return [UIImage imageNamed:name];
    }
}
Run Code Online (Sandbox Code Playgroud)

该文件是正确的,但图像的大小是错误的.

如果系统(使用[UIImage imageNamed:@"bg.png"])自动选择文件,则在iPhone视网膜上,大小仍为320x480(1点= 4像素).

但如果我使用[Helper imageNamed:@"bg.png"],尺寸为640x960.(1分= 1像素)

那么无论如何要改正尺寸?

iphone ipad ios retina-display

1
推荐指数
2
解决办法
1805
查看次数