小编nhg*_*rif的帖子

使用 Java Swing 进行双缓冲留下痕迹

我正在从事的项目旨在展示一个.gif带有背景的可移动物体。目前,如果我使用的super.paint(g);话,角色和背景画就会闪烁。如果我不这样做,那么它会留下像所包含的图像一样的痕迹。我不知道为什么会发生这种情况,需要帮助。

使用java swing进行图像动画

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.border.EmptyBorder;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JLabel;

public class keyboardinput extends JFrame implements ActionListener, KeyListener {
    private JPanel contentPane;

    private Image playerModelRight;
    private Image playerModelLeft;
    private Image playerModelAttackRight;
    private Image playerModelAttackLeft;
    private Image playerModelStandRight;
    private Image playerModelStandLeft;
    private Image background;
    private Image doubleBuffer;

    private int direction;

    private Timer …
Run Code Online (Sandbox Code Playgroud)

java swing

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

检查NSString是否只是字母

确保NSString仅包含字母az和AZ的最佳方法是什么.

我已经尝试了以下代码,但由于某些原因它不起作用:

NSString *myegex = @"[A-Za-z]";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", myregex];
if (![emailTest evaluateWithObject:self.initials.text])  {
     // print error
     return;
}
Run Code Online (Sandbox Code Playgroud)

regex objective-c nsstring

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

iOS 8 Swift CS193P计算器错误开关操作

我刚开始用斯坦福教程学习Swift.我有Xcode 6.3.2.我在操作中遇到了一个错误,switch无法理解如何解决它.

我也附了一个截图

@IBAction func operate(sender: UIButton) {
        let operation = sender.currentTitle!
        if userIsInTheMiddleOfTypingANumber{
        enter()
        }
        switch operation{

        case "?": performOperation {$0+$1}

        case "??": performOperation {$0*$1}

        case "?": performOperation {$1/$0}

        case "?": performOperation {$1-$0}

        default:break
        }

    }
    private func performOperation(operation : (Double,Double)->Double){
        if(operandStack.count>=2){
            DisplayValue = operation(operandStack.removeLast(),operandStack.removeLast())
            enter()
        }

    }
Run Code Online (Sandbox Code Playgroud)

Xcode错误

ios swift

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

[NSNull length]:无法识别的选择器发送到objective-c中的实例

我从服务获取一些JSON数据,一个属性是表示图像URL的字符串,似乎返回的是NULL,我做检查但是XCode在我的if语句之前中断并生成异常.这是我的代码如下:

- (void)configureCellForAlbum:(Album *)album {

    self.albumTitle.text = album.albumTitle;
    self.artisteName.text = album.artisteName;
    NSURL *imageUrl = [NSURL URLWithString:album.thumbnail];
    if (imageUrl == nil) {
        self.albumThumbnail.image = [UIImage imageNamed:@"music_record"];
    }
    else {
        self.albumThumbnail.imageURL = imageUrl;
    }
}
Run Code Online (Sandbox Code Playgroud)

例外是

由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [NSNull length]:发送到实例的无法识别的选择器.

我如何进行检查,以便如果值为null,则使用本地图像但如果不为null则使用返回的图像字符串url?

objective-c ios

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

无法使用PureLayout设置滚动视图

viewDidLoadUIViewController子类中有以下方法实现:

var scrollView  = UIScrollView.newAutoLayoutView()
var contentView = UIView.newAutoLayoutView()

override func viewDidLoad() {
    super.viewDidLoad()

    view.addSubview(scrollView)
    scrollView.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsetsZero)

    scrollView.addSubview(contentView)
    contentView.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsetsZero)
    contentView.autoMatchDimension(.Height, toDimension: .Height, ofView: view)
    contentView.autoMatchDimension(.Width, toDimension: .Width, ofView: view)

    contentView.addSubview(customView)
    customView.autoPinEdgeToSuperviewEdge(.Top, withInset:0)
    customView.autoPinEdgeToSuperviewEdge(.Left, withInset:15)
}
Run Code Online (Sandbox Code Playgroud)

但是,当我运行应用程序时,内容不会滚动.我发现很少有PureLayout文档和示例,并且没有关于滚动视图的清楚.有人可以帮我这个吗?

uiscrollview ios autolayout swift pure-layout

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

如!vs作为Swift中Xcode 6.3的运算符

Swift在Xcode 6.3中发生了很大的变化.我不得不在我的每个应用程序中替换几十个地方as- > as!.为什么,现在的规则是什么?

casting swift

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

无法从iOS模拟器获取位置

我试图通过简单的快速代码使用iOS模拟器获得位置.但是在调试会话中,不会调用回调函数.我将虚拟位置设置为iOS模拟器.

//  ViewController.swift
//  helloWorld
//
//  Created by  on 5/17/15.
//  Copyright (c) 2015   All rights reserved.
//

import UIKit
import CoreLocation

class ViewController: UIViewController, CLLocationManagerDelegate {

    var locMan: CLLocationManager!
    var lat: CLLocationDegrees!
    var lng: CLLocationDegrees!
    var hasPosData: Bool

    required init(coder aDecoder: NSCoder) {
        locMan  = CLLocationManager()
        lat = CLLocationDegrees()
        lng = CLLocationDegrees()
        hasPosData = false
        super.init(coder: aDecoder)
    }

    func retreiveCurrentPos(){
        locMan.delegate = self
        locMan.requestAlwaysAuthorization()

        // start using GPS function
        locMan.startUpdatingLocation()
    }

    func saveResult2File(){
        var contents: String

        let dirToSave …
Run Code Online (Sandbox Code Playgroud)

core-location ios swift

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

有人可以帮我将 Objective C 转换为 Swift

我试图理解这种转换,但我只是不明白。

RVConfig *config = [RVConfig defaultConfig];
Rover *rover = [Rover setup:config];
[rover startMonitoring];
Run Code Online (Sandbox Code Playgroud)

这是我所拥有的

RVConfig.defaultConfig()
Rover.setup(config: Rover(rover)
Rover.startMonitoring(Rover)
Run Code Online (Sandbox Code Playgroud)

swift

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

对于具有定时迭代的循环 - Objective-C

我想实现一个for循环,这样对于每次迭代,它将等待一秒钟才能进入下一个循环.

for (NSUInteger i = 0; i <=3; i++) {
   //...do something
   //...wait one second
}
Run Code Online (Sandbox Code Playgroud)

iteration objective-c

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

将变量从一个Swift类传递到另一个Swift类的最佳方法?

假设我在一个类中定义变量ViewController,并且想要从另一个类访问该变量,比如说BLEHandler.我该怎么做呢?我遇到了麻烦NSUserDefaults,所以除此之外的方法将不胜感激.

nsuserdefaults ios swift

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

Objective C异步到同步数据库访问

我找到了一个用于连接Microsoft SQL Server数据库的开源Objective-C库.

问题是,我想同步使用它.

这就是我的Swift项目使用库的方式.

func execute(query: String) {

    self.client.connect(host + ":" + port, username: username, password: password, database: database) { (connected) -> Void in
        if connected {
            self.client.execute(query, completion: { (results: Array<AnyObject>!) -> Void in
                self.result = results[0] as! Array<AnyObject>
            })
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

传递的块由库异步执行.有没有办法让代码同步执行,这样每当我调用时execute,该线程在execute返回之前等待库工作完成?

sql asynchronous swift

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

迅速吊装?

众所周知,JavaScript"将"变量"提升"到文件或范围的顶部.但根据我的理解,使用let是相同的,var只是let局限于它所定义的范围.

作为一种编译语言而不是解释,我们可以假设Swift不这样做吗?

例如:

x = 10

var y = x + 10

var x
Run Code Online (Sandbox Code Playgroud)

hoisting swift

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