我正在socket.io我的swift ios应用程序中实现.
目前在几个面板上我正在监听服务器并等待收到的消息.我这样做是通过调用getChatMessage每个面板中的函数来实现的:
func getChatMessage(){
SocketIOManager.sharedInstance.getChatMessage { (messageInfo) -> Void in
dispatch_async(dispatch_get_main_queue(), { () -> Void in
//do sth depending on which panel user is
})
}
}
Run Code Online (Sandbox Code Playgroud)
但是我注意到这是一个错误的方法,我需要更改它 - 现在我想开始只收听一次传入消息,当任何消息到来时 - 将此消息传递给任何监听它的面板.
所以我想通过NSNotificationCenter传递传入的消息.到目前为止,我能够传递发生的事情的信息,但不能传递数据本身.我是这样做的:
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.showSpinningWheel(_:)), name: showSpinner, object: nil)
Run Code Online (Sandbox Code Playgroud)
然后我有一个叫做的函数:
func showSpinningWheel(notification: NSNotification) {
}
Run Code Online (Sandbox Code Playgroud)
任何时候我想打电话给我:
NSNotificationCenter.defaultCenter().postNotificationName(hideSpinner, object: self)
Run Code Online (Sandbox Code Playgroud)
那么如何传递对象messageInfo并将其包含在被调用的函数中?
我试着按照这个教程.
这就是我在控制台中所做的:
pip3 install --user --upgrade awscli
Run Code Online (Sandbox Code Playgroud)
在那之后,当我写:
pip3 --version
Run Code Online (Sandbox Code Playgroud)
我越来越:
pip 9.0.1 from /Users/user/Library/Python/3.4/lib/python/site-packages (python 3.4)
Run Code Online (Sandbox Code Playgroud)
然后我写道:
pip3 install --user --upgrade awscli
Run Code Online (Sandbox Code Playgroud)
此命令已下载awscli并自动添加:
# Setting PATH for Python 3.4
# The orginal version is saved in .profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH
Run Code Online (Sandbox Code Playgroud)
对我的 .profile
后来,为了确定,我写道:
source ~/.profile
Run Code Online (Sandbox Code Playgroud)
然后当我输入:
user$ aws
-bash: aws: command not found
Run Code Online (Sandbox Code Playgroud)
我也没有运气重新启动终端.
这有什么问题?
我有以下 html 代码:
<div class="container">
<form name="queryForm" class="form-inline text-center">
<p class="checkbox-inline">
<input type="checkbox" name="optionsRadios" id="checkOther" value="other" ng-model="formData.other" ng-true-value="'other'" ng-init="formData.other='other'">Other</p>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
结果是:
将此颜色更改为给定颜色的最简单方法是什么,例如 D7B1D7?
我创建了这个小提琴,因为你可以看到我有一个有两个文本的网页,一个在另一个下面.它在宽屏幕上运行良好,但是当我收缩网页 - 或者在移动设备上运行网页时 - 它就搞砸了,就像在这个屏幕截图上一样:
我想通过添加CSS移动查询来提高响应速度,但是在我的代码中:
@media (max-width: 545px) {
.outer{
width:100%;
height:330px;
top:0;
position:relative;
}
.inner1{
width:100%;
height:320px;
margin-bottom:0px;
}
.inner2{
width:100%;
height:330px;
margin-bottom:0px;
}
}
@media (max-width: 435px) {
.outer{
width:100%;
height:380px;
top:0;
position:relative;
}
.inner1{
width:100%;
height:370px;
margin-bottom:0px;
}
.inner2{
width:100%;
height:380px;
margin-bottom:0px;
}
}
@media (max-width: 378px) {
.outer{
width:100%;
height:460px;
top:0;
position:relative;
}
.inner1{
width:100%;
height:450px;
margin-bottom:0px;
}
.inner2{
width:100%;
height:460px;
margin-bottom:0px;
}
}
Run Code Online (Sandbox Code Playgroud)
等等,所以很多不同的屏幕宽度值.我怀疑还有其他方法可以做到这一点,我不需要在移动CSS中单独覆盖每个屏幕宽度的响应方式...你能给我任何提示我怎么能改变我的代码所以它独立工作任何设备/屏幕宽度?谢谢!
这是我UISegmentedControl在Swift中写的:
我用以下代码创建了它:
let selectedAttributes: NSDictionary = [
NSForegroundColorAttributeName: UIColor.black,
NSFontAttributeName: fontForSegmentedControl!
]
let normalAttributes: NSDictionary = [
NSForegroundColorAttributeName: UIColor.gray,
NSFontAttributeName: fontForSegmentedControl!
]
mySegmentedControl.setTitleTextAttributes(selectedAttributes as [NSObject : AnyObject], for: UIControlState.selected)
mySegmentedControl.setTitleTextAttributes(normalAttributes as [NSObject : AnyObject], for: UIControlState.normal)
Run Code Online (Sandbox Code Playgroud)
删除边框的扩展名在这里:
extension UISegmentedControl {
func removeBorders() {
setBackgroundImage(imageWithColor(color: UIColor.white/*backgroundColor!*/), for: .normal, barMetrics: .default)
setBackgroundImage(imageWithColor(color: tintColor!), for: .selected, barMetrics: .default)
setDividerImage(imageWithColor(color: UIColor.clear), forLeftSegmentState: .normal, rightSegmentState: .normal, barMetrics: .default)
}
// create a 1x1 image with this color
private func imageWithColor(color: UIColor) -> UIImage …Run Code Online (Sandbox Code Playgroud) 我正在看Ray Rayderlich教程http://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial他正在使用这个函数:
class func fromJSON(json: [JSONValue]) -> Artwork? {
// 1
var title: String
if let titleOrNil = json[16].string {
title = titleOrNil
} else {
title = ""
}
let locationName = json[12].string
let discipline = json[15].string
// 2
let latitude = (json[18].string! as NSString).doubleValue
let longitude = (json[19].string! as NSString).doubleValue
let coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
// 3
return Artwork(title: title, locationName: locationName!, discipline: discipline!, coordinate: coordinate)
}
Run Code Online (Sandbox Code Playgroud)
由于我在我的项目中使用SwiftyJSON,我想继续使用它,所以我考虑基于此重写这个功能.
如果我理解正确,这个函数需要一个json节点并Artwork从中创建对象.
那么如何使用SwiftyJSON引用单个json节点?
我试过做:
class …Run Code Online (Sandbox Code Playgroud) 我有一个数据库,我分配了一个我想要立即删除的用户.
我的命令如下:
> show dbs
admin 0.000GB
users 0.000GB
local 0.000GB
> use admin
switched to db admin
> show users
{
"_id" : "admin.root",
"user" : "root",
"db" : "admin",
"roles" : [
{
"role" : "readWriteAnyDatabase",
"db" : "admin"
},
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "dbAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "clusterAdmin",
"db" : "admin"
}
]
}
{
"_id" : "admin.myuser",
"user" : "myuser",
"db" : "admin",
"roles" : …Run Code Online (Sandbox Code Playgroud) 我正在编写一个应用程序,我有一个嵌入式mapview来显示用户的位置.到目前为止这是我的代码:
class YourCurrentLocation: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var mapView: MKMapView!
var locationManager = CLLocationManager()
let regionRadius: CLLocationDistance = 1000
func checkLocationAuthorizationStatus() {
if CLLocationManager.authorizationStatus() == .AuthorizedWhenInUse {
mapView.showsUserLocation = true
centerMapOnLocation(locationManager.location!, map: mapView, radius: regionRadius)
} else {
locationManager.requestAlwaysAuthorization() //requestWhenInUseAuthorization()
}
}
func centerMapOnLocation(location: CLLocation, map: MKMapView, radius: CLLocationDistance) {
let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate,
radius * 2.0, radius * 2.0)
map.setRegion(coordinateRegion, animated: true)
}
override func viewDidLoad() {
super.viewDidLoad()
// mapView.delegate = self
if CLLocationManager.locationServicesEnabled()
{
//locationManager = CLLocationManager() …Run Code Online (Sandbox Code Playgroud) 在我的html代码中,我定义了以下列表:
<p class="list">first.</p>
<p class="list">second.</p>
Run Code Online (Sandbox Code Playgroud)
现在,css我有:
.list {
display: table;
}
.list:before {
display: table-cell;
counter-increment: counter;
content: counter(counter) '.';
padding-right: 5px;
}
Run Code Online (Sandbox Code Playgroud)
并且页面上的结果是:
1. first
1. second
Run Code Online (Sandbox Code Playgroud)
如何将第二个数字增加到2的值?
在我的'Swift'应用程序中,我有一个将照片上传到我的Amazon S3存储桶的功能.当用户连接到WiFi或LTE没有问题,但是当连接速度稍慢(例如3G)时,上传需要花费很多时间(最多一分钟),而iphone可能会损失15-20%的电池!我将照片调整到大约200-300kb,这应该不是问题.我用它的代码是:
func awsS3PhotoUploader(_ ext: String, pathToFile: String, contentType: String, automaticUpload: Bool){
let credentialsProvider = AWSCognitoCredentialsProvider(regionType:CognitoRegionType,
identityPoolId:CognitoIdentityPoolId)
let configuration = AWSServiceConfiguration(region:CognitoRegionType, credentialsProvider:credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
let uploadRequest = AWSS3TransferManagerUploadRequest()
uploadRequest?.body = URL(string: "file://"+pathToFile)
uploadRequest?.key = ProcessInfo.processInfo.globallyUniqueString + "." + ext
uploadRequest?.bucket = S3BucketName
uploadRequest?.contentType = contentType + ext
uploadRequest?.uploadProgress = { (bytesSent, totalBytesSent, totalBytesExpectedToSend) -> Void in
DispatchQueue.main.async(execute: { () -> Void in
if totalBytesExpectedToSend > 1 {
print(totalBytesSent)
print(totalBytesExpectedToSend)
}
}) …Run Code Online (Sandbox Code Playgroud) ios ×5
swift ×5
css ×3
html ×2
swift3 ×2
amazon-s3 ×1
aws-cli ×1
css-counter ×1
css-tables ×1
javascript ×1
jquery ×1
list ×1
macos ×1
mapkit ×1
mkmapview ×1
mongodb ×1
pip ×1
swifty-json ×1
terminal ×1