我有一个在scree周围弹跳的球,就像乒乓球一样.
球的半径取决于屏幕的大小.
我发现在iPhone和iPad上球的速度并不相同.
因为iPad上的球更大,所以它更大ball.physicsBody.mass.
问题
如何正确解决这个问题?
我找到了两种方法:
首先是:SpriteKit iPhone/iPad的分辨率不同,需要同样的物理变化SKPhysicsWorld.第二是:SpriteKit球速大小与mass球的固定不同.
我认为固定mass球是正确的方法.
我对么 ?
假设我有这个代码:
import sys
from datetime import date time
startDate = datetime.strptime(sys.argv[1], '%d.%m.%Y') # e.g. 05.06.2001 DD.MM.YYYY
endDate = datetime.strptime(sys.argv[2], '%d.%m.%Y') # e.g. 25.05.2005
Run Code Online (Sandbox Code Playgroud)
如何获得这两个日期之间的所有年份,包括开始和结束年份,如
[2001, 2002, 2003, 2004, 2005]
Run Code Online (Sandbox Code Playgroud) 我在swift中写了我的第一个扩展名.
这是代码:
extension String
{
// add padding
// source: http://zh-wang.github.io/blog/2014/09/25/learning-swift-part-6/
func alignRight(count: Int, pad: Character) -> String
{
let amountToPad = count - countElements(self)
if amountToPad < 1 {
return self
}
let padString = String(pad)
var string = self
for _ in 1...amountToPad {
string = padString + string
}
return string
}
}
Run Code Online (Sandbox Code Playgroud)
这工作正常,我这样使用它:
let a = "ddd"
let b = a.alignRight(5, pad: "0") // b is 00ddd
Run Code Online (Sandbox Code Playgroud)
我想知道是否有可能这样做
var a = "ddd"
a.alignRight(5, pad: "0") // …Run Code Online (Sandbox Code Playgroud) 如何在没有编程的情况下返回上一个视图UINavigationController,因为我找到的所有示例都使用了UINavigationController?
我正在查看发送反馈,我想在更多应用程序中使用此视图.
如果我使用UINavigationController而不是app需要UINavigationController使用我的视图来发送反馈.
这可能吗?怎么做?
这是代码我如何显示发送反馈的视图:
- (IBAction)showFeedbackView:(id)sender {
WOC_FeedbackViewController *feedbackView = [[WOC_FeedbackViewController alloc] init];
[self presentViewController:feedbackView animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud) 我使用以下代码来匹配所有具有CSS类"ad_item"的div.
soup.find_all('div',class_="ad_item")
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,在该网页上,还有将CSS类设置为"ad_ex_item"和"ad_ex_item"的div.
<div class="ad_item ad_ex_item">
Run Code Online (Sandbox Code Playgroud)
当您搜索与某个CSS类匹配的标记时,您将匹配其任何CSS类:
那么我如何匹配div,只有"ad_item",并且没有"ad_ex_item".
或者换句话说,如何搜索只有CSS类"ad_item"的div?
我有UTF-8文件,我想用一些HTML标签替换一些2字节的字符.
我想为此制作Python脚本.只需读取文件,char by char,然后输入if等等.
我遇到的问题是,如果我通过char读取char,我正在读取一个字节,但有些字符是1字节,有些是2字节长.
怎么解决?
我基本上需要通过char读取char的功能,但它会知道这个char大小为1或2个字节.
假设我有一个包含3个数字的数组:
NSArray *array = @[@1, @2, @3];
Run Code Online (Sandbox Code Playgroud)
而且我想在不重复的情况下完成所有组合.
所以我需要的是:
(1)
(2)
(3)
(1,2)
(2,3)
(1,3)
(1,2,3)
我当前的代码是这样的:
NSArray *array = @[@1, @2, @3];
int numberOfCardsOTable = [array count];
//NSLog(@"array = %@", array);
for (int lenghtOfArray = 1; lenghtOfArray <= numberOfCardsOTable; lenghtOfArray++)
{
for (int i = 0; i < numberOfCardsOTable; i++)
{
// array bound check
if (i + lenghtOfArray > numberOfCardsOTable) {
continue;
}
NSArray *subArray = [[NSMutableArray alloc] init];
subArray = [array subarrayWithRange:NSMakeRange(i, lenghtOfArray)];
NSLog(@"array = %@", subArray); …Run Code Online (Sandbox Code Playgroud) 我想用
for (TBL_CardView *cardView in cardsInHand)
{
// <#statements#>
}
Run Code Online (Sandbox Code Playgroud)
TBL_CardView是我的自定义类,而且cardsInHand只是(TBL_CardViewArray*)
所以我需要countByEnumeratingWithState:objects:count:为我的TBL_CardViewArray班级实施.
它是否正确 ?
这是我的TBL_CardViewArray.h
/**
* Keep TBL_CardView in array
*/
@interface TBL_CardViewArray : NSObject
- (TBL_CardView *)drawCard;
- (void)addCard:(TBL_CardView *)card;
- (NSUInteger)cardsRemaining;
- (NSArray*) cardViewArray;
- (TBL_CardView *)drawRandomCard;
@end
Run Code Online (Sandbox Code Playgroud)
来自TBL_CardViewArray.m的一些重要部分
@implementation TBL_CardViewArray
{
NSMutableArray *_cards;
}
Run Code Online (Sandbox Code Playgroud)
所以我只是使用TBL_CardViewArrayNSMutableArray的包装来存储我的TBL_CardView类.
问题
如何实现countByEnumeratingWithState:objects:count:用于我的TBL_CardViewArray类.
我确实谷歌它,但没有找到一些我可以轻松重用的例子.
我的假设是因为我已经在使用NSMutableArray存储它并不是那么复杂,但我无法弄清楚如何?
在我的*.h文件中,我有foo一个readonly属性.
我通过使用更新该属性赢得一些其他公共方法_foo = _foo + 1;
现在我在*.h文件上有类别.
我需要foo从类别更新属性.
如果我使用_foo然后我得到Use of undeclared identifier '_foo''
如果我使用self.foo = 5然后我得到Assignment to readonly property
我知道我可以通过将foo属性设置为readwrite 来解决这个问题,但我想避免这种情况.
问题
如何解决?
也可以从类外部将属性设置为只读,但是从类和类别中读取是否可以?
那样可以解决这个问题.
我有NSTimer的经验,每分钟运行一次,比如
NSTimer.scheduledTimerWithTimeInterval(60.0, target: self, selector: Selector("everyMinute"), userInfo: nil, repeats: true)
Run Code Online (Sandbox Code Playgroud)
是否可以使用NSTimer,其他一些类或其他控件,每分钟运行一些方法但是在第一分钟?
我确实知道如何自己实现它,但我首先检查这已经存在了吗?
ios ×6
objective-c ×5
python ×3
swift ×2
date ×1
game-physics ×1
math ×1
nsarray ×1
python-2.7 ×1
sprite-kit ×1
utf ×1
web-scraping ×1