我正在制作一个群聊应用程序,并且我有与用户相关联的图像,所以每当他们说话时,他们的图像就会显示在它旁边。我用 python 编写了服务器,客户端将是一个 iOS 应用程序。我使用字典来存储所有的消息/图像对。每当我的 iOS 应用程序向服务器 ( msg:<message
)发送命令时,字典都会像这样将图像和消息添加到字典中:dictionary[message] = imageName
,它被转换为列表,然后在套接字中发送字符串。我想将传入的消息添加到字典的开头,而不是结尾。就像是
#When added to end:
dictionary = {"hello":image3.png}
#new message
dictionary = {"hello":image3.png, "i like py":image1.png}
#When added to start:
dictionary = {"hello":image3.png}
#new message
dictionary = {"i like py":image1.png, "hello":image3.png}
Run Code Online (Sandbox Code Playgroud)
有没有办法将对象添加到字典的开头?
我有一个简单的困境.我的应用程序中有一个UICollectionViewController,显示已保存的测验.我有加载权限,但我希望它移动检测其中一个的点击然后做逻辑将其加载到主VC中.我希望选择类似于UITableViewCell,它突出显示它一秒钟,然后取消它.如果有帮助,我正在使用子类UICollectionViewCell.
我是SceneKit的新手,正在开始测试应用程序.我有一个移动的小立方体.我想添加轴(X,Y,Z).我是这样创造的.
SCNVector3 xPositions[] = {SCNVector3Make(-50, 0, 0), SCNVector3Make(50, 0, 0)};
int indicies[] = {0, 1};
NSData *indexData = [NSData dataWithBytes:indicies length:sizeof(indicies)];
// X axis
SCNGeometrySource *xSource = [SCNGeometrySource geometrySourceWithVertices:xPositions count:2];
SCNGeometryElement *xElement = [SCNGeometryElement geometryElementWithData:indexData primitiveType:SCNGeometryPrimitiveTypeLine primitiveCount:2 bytesPerIndex:sizeof(int)];
SCNGeometry *xAxis = [SCNGeometry geometryWithSources:@[xSource] elements:@[xElement]];
SCNNode *xNode = [SCNNode nodeWithGeometry:xAxis];
[self.gameView.scene.rootNode addChildNode:xNode];
// Y axis
SCNVector3 yPositions[] = {SCNVector3Make(0, -50, 0), SCNVector3Make(0, 50, 0)};
SCNGeometrySource *ySource = [SCNGeometrySource geometrySourceWithVertices:yPositions count:2];
SCNGeometryElement *yElement = [SCNGeometryElement geometryElementWithData:indexData primitiveType:SCNGeometryPrimitiveTypeLine primitiveCount:2 bytesPerIndex:sizeof(int)];
SCNGeometry *yAxis = …
Run Code Online (Sandbox Code Playgroud) 我有一个相当简单的问题.我将如何以编程方式添加/删除任务控制中找到的工作空间.我在这里看过这篇关于以编程方式更改到另一个空间的帖子,我认为它可能类似于答案,使用CGSPrivate.h
.我不需要担心私有框架,因为它不会在应用商店中出现.
编辑:我也看到一篇关于修改com.apple.spaces.plist
和添加工作区的帖子,但我不知道如何添加它,因为dict有UUID和其他东西.
对于我的代码,我尝试AXMenuItems
从AXMenu
(AXUIElementRef
)获取数组。菜单成功登录,这是我的代码:
NSArray *anArray = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.dock"];
AXUIElementRef anAXDockApp = AXUIElementCreateApplication([[anArray objectAtIndex:0] processIdentifier]);
CFTypeRef aChildren;
AXUIElementCopyAttributeValue(anAXDockApp, kAXChildrenAttribute, &aChildren);
SafeCFRelease(anAXDockApp);
CFTypeRef aMenu = CFArrayGetValueAtIndex(aChildren, 0);
NSLog(@"aMenu: %@", aMenu);
// Get menu items
CFTypeRef aMenuChildren;
AXUIElementCopyAttributeValue(aMenu, kAXVisibleChildrenAttribute, &aMenuChildren);
for (NSInteger i = 0; i < CFArrayGetCount(aMenuChildren); i++) {
AXUIElementRef aMenuItem = [self copyAXUIElementFrom:aMenu role:kAXMenuItemRole atIndex:i];
NSLog(@"aMenuItem: %@", aMenuItem); // logs (null)
CFTypeRef aTitle;
AXUIElementCopyAttributeValue(aMenuItem, kAXTitleAttribute, &aTitle);
if ([(__bridge NSString *)aTitle isEqualToString:@"New Window"] || [(__bridge NSString *)aTitle isEqualToString:@"New …
Run Code Online (Sandbox Code Playgroud) 我得到分辨率为 1920x1080 的图像。我试图将它们裁剪到中心正方形区域(即中心的 1080x1080 正方形)。该决议将来可能会发生变化。可以用这种方式裁剪图像吗?我已经尝试了一些发布在 SO 上的东西,但是如果我尝试裁剪然后居中,我总是会得到一个 660x1080 的图像。这是一张描绘我想要实现的目标的图像。
基本上红色是原始的,绿色是我想要的,黄色只是显示 mixX 和 midY 线。
我试过的代码。
func imageByCroppingImage(image: UIImage, toSize size: CGSize) -> UIImage{
let newCropWidth: CGFloat?
let newCropHeight: CGFloat?
if image.size.width < image.size.height {
if image.size.width < size.width {
newCropWidth = size.width
} else {
newCropWidth = image.size.width
}
newCropHeight = (newCropWidth! * size.height) / size.width
} else {
if image.size.height < size.height {
newCropHeight = size.height
} else {
newCropHeight = image.size.height
}
newCropWidth = (newCropHeight! * size.width) / …
Run Code Online (Sandbox Code Playgroud) 我有一个用numpy创建的3d数组,我想知道如何将其旋转自定义角度,而不仅仅是rot90
numpy 的功能。有人可以帮忙吗?
3d矩阵表示图像(例如立方体或其他形状),即
0:
1 1 1
1 1
1 1 1
1:
1 1
1 1
2:
1 1 1
1 1
1 1 1
Run Code Online (Sandbox Code Playgroud)
编辑:移动解决方案来回答
我在 UIViewController 中有一个 UITableView 显示视频。当我向下滚动时,我想制作从大标题到小标题的动画。我目前使用的代码:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if #available(iOS 11.0, *) {
UIView.animate(withDuration: 0.35, animations: {
if scrollView.contentOffset.y <= 128 {
self.navigationItem.largeTitleDisplayMode = .always
} else {
self.navigationItem.largeTitleDisplayMode = .never
}
})
}
}
Run Code Online (Sandbox Code Playgroud)
但过渡时显得很神经质。有什么更好的方法来做到这一点?
cocoa ×3
ios ×3
macos ×2
objective-c ×2
python ×2
swift ×2
chat ×1
crop ×1
dictionary ×1
highlight ×1
ios11 ×1
menu ×1
numpy ×1
parent-child ×1
prepend ×1
scenekit ×1
swift3 ×1
uiimage ×1
uitableview ×1
workspace ×1