我在斯威夫特做一个游戏.我希望能够使用GameCenter发布用户的分数,以便可以看到所有用户的分数.但是,我花了一天时间试图弄清楚如何做到这一点,但我没有找到任何有用的指示.
我对iOS编程和Swift都很陌生,而且关于这个主题的信息非常少,所有这些都是用Objective-C编写的.
任何人都可以帮我将GameCenter集成到我的应用程序中,这样我就可以将用户分数发布到排行榜上供人们查看吗?
编辑:我已经在iTunesConnect上创建了一个GameCenter排行榜.
编辑2:我尝试过以下教程:http://www.appcoda.com/ios-game-kit-framework/并将其转换为Swift.我转换了这个:
-(void)authenticateLocalPlayer {
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
if (viewController != nil) {
[self presentViewController:viewController animated:YES completion:nil];
}
else{
if ([GKLocalPlayer localPlayer].authenticated) {
_gameCenterEnabled = YES;
// Get the default leaderboard identifier.
[[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) {
if (error != nil) {
NSLog(@"%@", [error localizedDescription]);
}
else{
_leaderboardIdentifier = leaderboardIdentifier;
}
}];
}
else {
_gameCenterEnabled = NO;
}
}
};
}
Run Code Online (Sandbox Code Playgroud)
进入这个:
func …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个绘图应用程序。我有一个自定义 UIView:
class DrawView: UIView {
var touch : UITouch!
var lastPoint : CGPoint!
var currentPoint : CGPoint!
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
touch = touches.first as! UITouch
lastPoint = touch.locationInView(self)
println(lastPoint)
}
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
touch = touches.first as! UITouch
currentPoint = touch.locationInView(self)
self.setNeedsDisplay()
lastPoint = currentPoint
}
override func drawRect(rect: CGRect) {
var context = UIGraphicsGetCurrentContext()
CGContextSetLineWidth(context, 5)
CGContextSetStrokeColorWithColor(context, UIColor.blueColor().CGColor)
CGContextSetLineCap(context, kCGLineCapRound)
CGContextBeginPath(context)
if lastPoint != nil {
CGContextMoveToPoint(context, lastPoint.x, …Run Code Online (Sandbox Code Playgroud) 我正在使用UIImagePicker让用户拍照。拍摄照片时,我希望他们平移和缩放图像以适合裁剪框的内部,以便将图像存储为正方形。
但是,裁剪图像时,似乎无法将其移动到(人像)图像的顶部和底部(如果为横向,则为左右)。
我曾尝试搜索,但似乎没有太多信息,但这似乎是一个大问题。
有人可以帮忙吗?
这是我正在使用的少量代码:
let imagePicker = UIImagePickerController()
imagePicker.allowsEditing = true
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
present(imagePicker, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
显然还有更多的代码,但这是主要部分。
用照片编辑:
因此,我希望能够移动/放大照片以选择要保存的任何正方形部分。但是,我无法从该位置移动它/不断回弹。
我可以放大,但是它仍然限制了我的顶部和底部边缘。
再次,它与photoLibrary一起使用。
我正在尝试创建一个MKPointAnnotation在地图视图上使用的自定义.它看起来非常像Apple的照片中使用的那个:
我将从服务器检索大量照片及其位置.然后我想显示一个类似上面的注释,注释中的图像.
我目前有一个程序可以MKPointAnnotation在正确的坐标上添加法线,也可以从服务器检索相关的照片.
我想要的就是让我MKPointAnnotation看起来像那样.
我尝试过其他答案,但我认为这有点不同,因为我想每次在模板上显示图像.
我有一个启用了清除按钮的UITextField。我也有一些代码可以在用户点击屏幕上其他任何地方时关闭键盘:
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
tap.cancelsTouchesInView = false
view.addGestureRecognizer(tap)
func dismissKeyboard() {
view.endEditing(true)
}
Run Code Online (Sandbox Code Playgroud)
问题在于该代码会干扰清除按钮,因此永远不会清除文本字段。如何防止点击手势识别器处理清除按钮的点击?
我有一个包含5个图像的UIScrollView.我想在滚动视图的底部添加一个UIPageControl,以便用户可以看到它们所在的页面.
这是滚动视图的代码:
self.helpScrollView.contentSize = CGSizeMake(320 * 5, 436);
UIImageView *image1 = [[UIImageView alloc] initWithFrame:CGRectMake(320 * 0, 0, 320, 436)];
image1.image = [UIImage imageNamed:[NSString stringWithFormat:
@"Guide Page One.png"]];
[self.helpScrollView addSubview:image1];
UIImageView *image2 = [[UIImageView alloc] initWithFrame:CGRectMake(320 * 1, 0, 320, 436)];
image2.image = [UIImage imageNamed:[NSString stringWithFormat:
@"Guide Page Two.png"]];
[self.helpScrollView addSubview:image2];
UIImageView *image3 = [[UIImageView alloc] initWithFrame:CGRectMake(320 * 2, 0, 320, 436)];
image3.image = [UIImage imageNamed:[NSString stringWithFormat:
@"Guide Page Three.png"]];
[self.helpScrollView addSubview:image3];
UIImageView *image4 = [[UIImageView alloc] initWithFrame:CGRectMake(320 * 3, 0, …Run Code Online (Sandbox Code Playgroud) 我正在使用Xcode的内置按钮类型"UIButtonTypeInfoLight"制作一个"信息"按钮.
这是我的代码:
self.helpButton= [UIButton buttonWithType:UIButtonTypeInfoLight];
[self.helpButton addTarget:self
action:@selector(showHelp)
forControlEvents:UIControlEventTouchUpInside];
self.helpButton.frame = CGRectMake(280.0, 440.0, 20, 20);
[self.view addSubview:self.helpButton];
Run Code Online (Sandbox Code Playgroud)
但是,有一个问题.我的应用包含一个包含3个不同视图控制器的滚动视图 一个蓝色,一个红色,一个绿色.
应用程序打开的页面上的图标看起来很好(蓝色):

但是,当我滑动到绿色或红色页面时,按钮似乎保持蓝色,并且不像我希望的那样透明:

我怎么能阻止它这样做?我只是希望图标透明?
我有一个输入,我希望用户被发送到另一个页面,其中包含URI中的输入值,以便我可以提取它.
这是我的输入设置方式:
<input name="date" id="datepicker" onchange="window.location.href = 'test.php?Date=' + document.getElementById("datepicker").value;">
Run Code Online (Sandbox Code Playgroud)
基本上,当更改日期时,应将日期添加到URI的末尾,并且应将用户发送到test.php,其中将提取值.但是,似乎没有添加该值.
有什么问题?
每次玩游戏时都不会发生这种情况,也许每5或10次播放一次.当游戏结束时,我从运行循环中移除我的CADisplayLink(我用它来设置游戏区域的动画,有点像Flappy Bird中的管道).然而,在少数情况下,它崩溃了.该行旁边有:
Thread 1: EXC_BAD_ACCESS (code=1, address=0x10)
Run Code Online (Sandbox Code Playgroud)
这是代码:
func endGame(r : String) {
UIView.animateWithDuration(0.4, delay: 0.2, options: .CurveLinear, animations: {
self.scoreLabel.alpha = 0
}, completion: {
(finished: Bool) in
self.scoreLabel.removeFromSuperview()
});
self.view.userInteractionEnabled = false
reason = r
println("Game Over!!!")
//Crashes on this line
blockUpdateDisplayLink.removeFromRunLoop(NSRunLoop.currentRunLoop(), forMode: NSRunLoopCommonModes)
shiftDisplayLink.removeFromRunLoop(NSRunLoop.currentRunLoop(), forMode: NSRunLoopCommonModes)
scoreTimer.invalidate()
UIView.animateWithDuration(0.0001, delay: 0.7, options: .CurveLinear, animations: {
}, completion: {
(finished: Bool) in
self.performSegueWithIdentifier("Game Over", sender: self)
});
}
Run Code Online (Sandbox Code Playgroud)
如果我注释掉第一个CADisplayLink部分,那么无论如何它都会在第二个部分崩溃.
这是堆栈跟踪:

它与上面的"线程1"错误相同.
到底是怎么回事??
我正试图在我的Swift游戏中实现Game Center.我有一个菜单视图控制器,用户可以按下"SCORES"按钮,它应该将它们带到Game Center视图控制器.
当按下按钮时,这是在菜单vc中运行的代码:
var gcViewController: GKGameCenterViewController = GKGameCenterViewController()
gcViewController.gameCenterDelegate = self
gcViewController.viewState = GKGameCenterViewControllerState.Leaderboards
gcViewController.leaderboardIdentifier = "VHS"
self.presentViewController(gcViewController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
我在Game Center vc中有代码,但我认为它没有机会运行.应用程序在此代码后停止执行(没有断点或错误,只是不允许我点击任何内容)并显示一条弹出消息,内容如下:
Game Center Unavailable
Player is not signed in
Run Code Online (Sandbox Code Playgroud)
我得到的唯一其他响应是在Xcode中,其中以下行打印到日志:
2014-08-29 14:10:33.157 Valley[2291:304785] 17545849:_UIScreenEdgePanRecognizerEdgeSettings.edgeRegionSize=13.000000
Run Code Online (Sandbox Code Playgroud)
我不知道这意味着什么或为什么Game Center不工作.任何人都可以帮忙吗?
ios ×9
swift ×7
xcode ×4
game-center ×2
objective-c ×2
annotations ×1
breakpoints ×1
button ×1
cgcontext ×1
javascript ×1
jquery ×1
keyboard ×1
mapkit ×1
mkmapview ×1
onchange ×1
php ×1
uibutton ×1
uiimage ×1
uiscrollview ×1
uiview ×1