可能重复:
Python中的三元条件运算符
var foo = (test) ? "True" : "False";
Run Code Online (Sandbox Code Playgroud)
这在Python中会是什么样子?
使用Python 2.7,如果这有所作为.
我如何保持这个范围?
原版的
var Base = new function() {
var canvas;
var context;
this.init = function()
{
console.log("Canvas: " + $("canvas")[0])
this.canvas = $("canvas")[0];
console.log("Context: " + this.canvas.getContext('2d'))
this.context = this.canvas.getContext('2d');
$(window).resize(handleWindowResize);
handleWindowResize();
};
function handleWindowResize()
{
console.log("Resize Canvas [" + this.canvas + "] to {width: " +
$(window).width() + "," + $(window).width() + "}");
this.canvas.width = $(window).width();
this.canvas.height = $(window).height();
}
}
$(window).load(function() { new Base.init() });
Run Code Online (Sandbox Code Playgroud)
输出继电器:
Canvas: [object HTMLCanvasElement]
Context: [object CanvasRenderingContext2D]
Resize Canvas [undefined] to {width: 1680,1680} …Run Code Online (Sandbox Code Playgroud) 我想我只是捕获起始UIAcceleration y值并将其与当前值进行比较然后"测量"但我并不确切地知道(1)这是正确的(2)数学应该是什么.
谢谢你的帮助.
更新:
这是我按照jrturton的建议使用的代码.
#import "ViewController.h"
@interface ViewController()
{
CMMotionManager *motionManager;
}
@end
@implementation ViewController
@synthesize angleLabel;
- (void)startMotion
{
if (motionManager == nil)
{
motionManager = [[CMMotionManager alloc] init];
}
motionManager = [[CMMotionManager alloc] init];
[motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMDeviceMotion *motion, NSError *error) {
angleLabel.text = [NSString stringWithFormat:@"%g", motion.attitude.pitch];
}];
}
- (void) stopMotion
{
if (motionManager)
{
[motionManager stopDeviceMotionUpdates];
}
motionManager = nil;
}
- (void)viewDidUnload {
[self setAngleLabel:nil];
[super viewDidUnload];
}
@end
Run Code Online (Sandbox Code Playgroud) 我试图通过他们的contactId查找联系人的电话号码,bll结果返回 - 电话号码:1
我尝试过围绕SO使用其他示例,但我一直在光标上得到0计数
Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, contactId);
Log.i(TAG, "Locate Contact by Id: " + contactId + " at Uri: " + uri.toString());
Cursor cursor = this.getContentResolver().query(uri, null, null, null, null);
try {
if (cursor.moveToFirst()) {
Log.i(TAG, "Phone Number: " + cursor.getString(cursor.getColumnIndex(Phone.NUMBER)));
}
} finally {
cursor.close();
}
Run Code Online (Sandbox Code Playgroud)