我在绘制一些用颜色描边的线条然后用另一条线填充它们的内部(它们形成一个多边形)时遇到了麻烦.
UIColor *houseBorderColor = [UIColor colorWithRed:(170/255.0) green:(138/255.0) blue:(99/255.0) alpha:1];
CGContextSetStrokeColorWithColor(context, houseBorderColor.CGColor);
CGContextSetLineWidth(context, 3);
// Draw the polygon
CGContextMoveToPoint(context, 20, viewHeight-19.5);
CGContextAddLineToPoint(context, 200, viewHeight-19.5); // base
CGContextAddLineToPoint(context, 300, viewHeight-119.5); // right border
CGContextAddLineToPoint(context, 120, viewHeight-119.5);
CGContextAddLineToPoint(context, 20, viewHeight-19.5);
// Fill it
CGContextSetRGBFillColor(context, (248/255.0), (222/255.0), (173/255.0), 1);
//CGContextFillPath(context);
// Stroke it
CGContextStrokePath(context);
Run Code Online (Sandbox Code Playgroud)
随着CGContextStrokePath
注释,我得到这个结果:
但是,如果我取消注释CGContextStrokePath
并填充多边形,颜色会溢出笔划:
你如何实现这样的结果(无需重做整个绘图程序两次):
在我的根控制器中,我有一个属性 CMMotionManager
@property (strong, nonatomic) CMMotionManager *MManager;
Run Code Online (Sandbox Code Playgroud)
在它的吸气器中我做懒惰的实例化.当控制器的视图加载时,我调用此方法
- (void)reloadAccelerometer {
NSLog(@"Away we go");
self.MManager.deviceMotionUpdateInterval = 10.0/60.0;
[self.MManager startDeviceMotionUpdatesToQueue:self.queue withHandler:^(CMDeviceMotion *motion, NSError *error) {
NSLog(@"Y values is: %f", motion.userAcceleration.y);
}];
}
Run Code Online (Sandbox Code Playgroud)
我看到"离开我们去" NSLog
然后立即应用程序崩溃,我得到这个线程日志
libsystem_platform.dylib`spin_lock$VARIANT$mp:
0x39a87814: movs r1, #1
libsystem_platform.dylib`OSSpinLockLock$VARIANT$mp + 2:
0x39a87816: ldrex r2, [r0]
0x39a8781a: cmp r2, #0
0x39a8781c: it ne
0x39a8781e: bne.w 0x39a893ec ; _OSSpinLockLockSlow$shim
0x39a87822: strex r2, r1, [r0]
0x39a87826: cmp r2, #0
0x39a87828: bne 0x39a87816 ; OSSpinLockLock$VARIANT$mp + 2
0x39a8782a: dmb ish
0x39a8782e: bx lr …
Run Code Online (Sandbox Code Playgroud) 我正在使用OS X的最新默认项目(10.11,Xcode 7.0).它使用故事板,层次结构如下:
Window Controller -> View Controller
Run Code Online (Sandbox Code Playgroud)
我想设置窗口的初始位置和帧大小.显然用户可以改变它,但我希望它从一些默认值开始.我已经尝试过子类化NSWindowController
,但这没有效果.
class WindowController: NSWindowController {
override func windowDidLoad() {
super.windowDidLoad()
guard let window = window else {
return
}
let windowOriginPoint = CGPoint(x: 0, y: 0)
let windowSize = CGSize(width: 800, height: 400)
window.setFrame(NSRect(origin: windowOriginPoint, size: windowSize), display: true)
print("windowDidLoad")
}
}
Run Code Online (Sandbox Code Playgroud)
这样做的正确方法是什么?
此错误仅出现在iOS7中 - 我无法设置UIButton以显示其选定状态.既不在模拟器上,也不在设备上.我错过了什么吗?
我很好奇为什么不设置backgroundColor
为红色?
@IBDesignable class CustomLabel: UIView {
let view = UIView()
func setup() {
backgroundColor = UIColor.red
view.backgroundColor = UIColor.green
view.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
addSubview(view)
}
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
}
Run Code Online (Sandbox Code Playgroud)
这是结果.
这就是我期望的样子.
我第一次尝试apiclient
为YouTube 设置Google ,并按照文档进行了测试(没有找到YouTube API的特定示例):
import json
from apiclient.discovery import build
service = build('youtube', 'v3', developerKey = 'tralalala')
videos = service.videos()
request = videos.list(part = '7lCDEYXw3mM') # some video id
response = request.execute()
json.dumps(response, sort_keys = True, indent = 4)
Run Code Online (Sandbox Code Playgroud)
我明白了
{
"error": {
"errors": [
{
"domain": "youtube.parameter",
"reason": "missingRequiredParameter",
"message": "No filter selected.",
"locationType": "parameter",
"location": ""
}
],
"code": 400,
"message": "No filter selected."
}
}
Run Code Online (Sandbox Code Playgroud)
显然,我缺少此功能filter
,但是我似乎无法在google-api-client-libraries.appspot.com文档中的任何位置找到它。我的意图是通过提供视频来获取视频详细信息id
。
我已将项目上传到GitHub,以便轻松复制问题.
我有一个测试场景,我想在这里定位一个对象(SCNBox
在这种情况下是一个)和屏幕一样宽.这是整个代码.
let scene = SCNScene()
let rootNode = scene.rootNode
// Box
let boxGeometry = SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0)
let boxMaterial = SCNMaterial()
boxMaterial.diffuse.contents = UIColor.redColor()
boxGeometry.firstMaterial = boxMaterial
let boxNode = SCNNode(geometry: boxGeometry)
boxNode.position = SCNVector3(
x: 0,
y: 0,
z: -1)
rootNode.addChildNode(boxNode)
// Camera
let camera = SCNCamera()
camera.zNear = 0
let cameraNode = SCNNode()
cameraNode.position = SCNVector3(
x: 0,
y: 0,
z: 0)
cameraNode.camera = camera
rootNode.addChildNode(cameraNode) …
Run Code Online (Sandbox Code Playgroud) 我正在玩我自己的pwd
命令.为了找到整个路径,我需要遍历inode
树直到我到达根,并且告诉我已经击中根的方法是检查inode
为.
和存储的相等数字..
.
但在我的Mac上似乎并非如此,至少如果你看下面的这个表.
dirent | stat | link to
-----------+------------+--------
34078072 | 34078072 | self
31103058 | 31103058 | parent
31103058 | 31103058 | self
31103020 | 31103020 | parent
31103020 | 31103020 | self
613497 | 613497 | parent
613497 | 613497 | self
603204 | 603204 | parent
603204 | 603204 | self
157433 | 157433 | parent
157433 | 157433 | self
2 | 2 | parent
2 …
Run Code Online (Sandbox Code Playgroud) 我有一个UIView
我正在尝试制作的简单子类@IBInspectable
。唯一的问题是我--
在属性检查器中看到的不是默认值。
@IBInspectable var cornerSize: CGSize = CGSize(width: 10, height: 10)
override init(frame: CGRect) {
super.init(frame: frame)
cornerSize = CGSize(width: 10, height: 10)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
cornerSize = CGSize(width: 10, height: 10)
}
override func awakeFromNib() {
super.awakeFromNib()
cornerSize = CGSize(width: 10, height: 10)
}
Run Code Online (Sandbox Code Playgroud)
这是一个屏幕截图。
我以为会是10
。
这是我的源代码./source/client/main.jsx
。
export default {
test: () => console.log('Flow')
};
Run Code Online (Sandbox Code Playgroud)
这是我的webpack.config.cjs
。
const path = require('path');
const webpack = require('webpack');
const packageJSON = require('./package.json');
module.exports = (env, argv) => {
return {
mode: 'development',
entry: './source/client/main.jsx',
// entry: './main.js',
output: {
path: path.join(__dirname, 'release'),
filename: 'main.js',
library: {
name: packageJSON.name,
type: 'umd'
}
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
'@babel/preset-react'
],
plugins: [ …
Run Code Online (Sandbox Code Playgroud) ios ×6
swift ×4
objective-c ×3
macos ×2
c ×1
cgcontext ×1
cocoa ×1
core-motion ×1
filesystems ×1
ibdesignable ×1
ios7 ×1
javascript ×1
python ×1
scenekit ×1
uibutton ×1
uiview ×1
webpack ×1
youtube-api ×1