我有一个tableview自定义单元格,storyboard使用标识符构建AutoLayout.
其中一个subviews需要是圆形的(layer.cornerRadius = width/2),它在开始时是一个正方形.
我试过layoutSubviews()但似乎在AutoLayout改变它的大小之前调用它...同样的事情didMoveToSuperview()
在AutoLayout更改了尺寸之后,将这样的内容更新到我的子视图的正确功能在哪里?
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell_small") as! Cell
...
return cell
}
// In Cell
override func layoutSubviews() {
rankLabel.layer.cornerRadius = rankLabel.bounds.width/2
rankLabel.layer.masksToBounds = true
}
override func didMoveToSuperview() {
rankLabel.layer.cornerRadius = rankLabel.bounds.width/2
rankLabel.layer.masksToBounds = true
}
Run Code Online (Sandbox Code Playgroud)
结果:

我正在尝试使用Camera2API将相机数据流式传输到SurfaceView.我正在按照本指南:Camera2指南
我无法过去 step 5
MainActivity.java::onCreate()
setContentView(R.layout.activity_main);
surfaceView = (SurfaceView)findViewById(R.id.surface);
manager = (CameraManager)getSystemService(Context.CAMERA_SERVICE);
Run Code Online (Sandbox Code Playgroud)
MainActivity.java::onClick()
for (String id : manager.getCameraIdList()) {
CameraCharacteristics characteristics = manager.getCameraCharacteristics(id);
Integer direction = characteristics.get(CameraCharacteristics.LENS_FACING);
if (direction != null && direction == CameraCharacteristics.LENS_FACING_BACK) {
if (checkCallingOrSelfPermission("android.permission.CAMERA") == PackageManager.PERMISSION_GRANTED)
manager.openCamera(id, new StateCallback(), null);
break;
}
}
Run Code Online (Sandbox Code Playgroud)
MainActivity.java.StateCallback :: onOpened(CameraDevice摄像头)
List<Surface> surfaces = new LinkedList<>();
surfaces.add(surfaceView.getHolder().getSurface());
CaptureRequest.Builder builder = camera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
builder.addTarget(surfaces.get(0));
camera.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(CameraCaptureSession session) {
Log.i(TAG, "Configured");
}
@Override …Run Code Online (Sandbox Code Playgroud) 我使用RoboSpice-Retrofit调用我的服务器REST api,直到几天前每次调用都抛出异常时,它一直没有问题,例如:
D/Retrofit: java.lang.NoSuchMethodError: No direct method <init>(Lcom/squareup/okhttp/OkHttpClient;Lcom/squareup/okhttp/Request;ZZZLcom/squareup/okhttp/Connection;Lcom/squareup/okhttp/internal/http/RouteSelector;Lcom/squareup/okhttp/internal/http/RetryableSink;Lcom/squareup/okhttp/Response;)V in class Lcom/squareup/okhttp/internal/http/HttpEngine; or its super classes (declaration of 'com.squareup.okhttp.internal.http.HttpEngine' appears in /data/app/com.company.app.customerapp-1/base.apk)
at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.newHttpEngine(HttpURLConnectionImpl.java:362)
at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.initHttpEngine(HttpURLConnectionImpl.java:312)
at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:377)
at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:497)
at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:73)
at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:38)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:321)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
at java.lang.reflect.Proxy.invoke(Proxy.java:393)
at $Proxy0.getTest(Unknown Source)
at com.adoperator.tidyapp.TestActivity$TestRequest.loadDataFromNetwork(TestActivity.java:67)
at com.adoperator.tidyapp.TestActivity$TestRequest.loadDataFromNetwork(TestActivity.java:54)
at com.octo.android.robospice.request.CachedSpiceRequest.loadDataFromNetwork(CachedSpiceRequest.java:48)
at com.octo.android.robospice.request.DefaultRequestRunner.processRequest(DefaultRequestRunner.java:150)
at com.octo.android.robospice.request.DefaultRequestRunner$1.run(DefaultRequestRunner.java:217)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
D/Retrofit: ---- END ERROR
Run Code Online (Sandbox Code Playgroud)
compile 'com.octo.android.robospice:robospice:1.4.14'
compile 'com.octo.android.robospice:robospice-cache:1.4.14'
compile 'com.octo.android.robospice:robospice-retrofit:1.4.14'
Run Code Online (Sandbox Code Playgroud)
我怀疑基于异常,编译器有问题,但我刚刚在另一台计算机上进行了测试,在同一个项目上安装了全新的Java和Android Studio,但同样的问题仍然存在......
这个错误让我发疯了......
任何人都知道任何有用的东西吗?任何帮助都非常感谢.
MainActivity.java:
SpiceManager …Run Code Online (Sandbox Code Playgroud) 我想发送一封电子邮件,但它给了我一个错误.
我有这个代码:
Sub sendMail(ByVal title As String, ByVal content As String)
Dim SmtpServer As New SmtpClient("smtp.gmail.com", 25)
SmtpServer.Credentials = New Net.NetworkCredential("name@gmail.com", "password")
Dim mail As New MailMessage("name@gmail.com", "name@gmail.com", title, content)
SmtpServer.Send(mail)
End Sub
Run Code Online (Sandbox Code Playgroud)
我有一个try catch试图调用这个方法,它不起作用所以catch运行,我得到了例外:System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. b6sm3176487lae.0 - gsmtp为什么我得到这个错误?以及如何解决?
我在iOS7中播放音频文件时遇到了一些问题.由于调用此代码时没有声音,因此无法播放音频文件:
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"PistolShootSound" ofType:@"mp3"]];
AVAudioPlayer *click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
[click setVolume:1.0];
[click play];
Run Code Online (Sandbox Code Playgroud)
但没有声音出来:(
我已经检查了计算机上的声音并且它正常工作,我已经在系统首选项中重新检查了"播放用户界面声音效果"选项但没有用.我试过像这样打开一个AVAudioSession:
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioSession setActive:YES error:nil];
Run Code Online (Sandbox Code Playgroud)
但这也不起作用.
还有另一种在iOS7中播放声音的方法吗?或者模拟器不再播放声音了吗?
我在SpriteKit的苹果示例代码中找到了几行
static const uint32_t missileCategory = 0x1 << 0;
Run Code Online (Sandbox Code Playgroud)
我知道什么static const是什么但是什么是uint32_t什么0x1 << 0意思?是某种十六进制?
我正在解析这个json:
{
"destination_addresses" : [ "Göteborg, Sverige" ],
"origin_addresses" : [ "Stockholm, Sverige" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "467 km",
"value" : 466568
},
"duration" : {
"text" : "4 timmar 34 min",
"value" : 16468
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
Run Code Online (Sandbox Code Playgroud)
变成NSDictionary这样:
let dataDict = NSJSONSerialization.JSONObjectWithData(data.dataUsingEncoding(NSUTF8StringEncoding), options: nil, error: nil) as NSDictionary
let distance = dataDict.valueForKeyPath("rows.elements.distance.value")
Run Code Online (Sandbox Code Playgroud)
现在,这可行,没有崩溃或错误.但是,我希望它会返回,466568但它会返回:
(
(
466568 …Run Code Online (Sandbox Code Playgroud) func getIndex<T: Equatable>(valueToFind: T) -> Int? {...}
mutating func replaceObjectWithObject<T: Equatable>(obj1: T, obj2: T) {
if let index = self.getIndex(obj1) {
self.removeAtIndex(index)
self.insert(obj2, atIndex: index) // Error here: 'T' is not convertible to 'T'
}
}
Run Code Online (Sandbox Code Playgroud)
我有这个函数,假设用另一个元素替换元素.但我不是很熟悉,Generics也不知道为什么这不起作用.请帮忙.
如果我从变异函数中删除Equatable,则错误消息会跳转到该func中的第一行,如果我然后用func替换它,find()它会给出与第3行相同的错误.
我有这个功能要从两个数字计算斜边
func hypotenusa<T>(nr1: T, nr2: T) -> T {
return sqrt( pow(nr1, 2) + pow(nr2, 2) )
}
// v Simpler situation v
func addition<T>(nr1: T, nr2: T) -> T {
return nr1 + nr2
}
Run Code Online (Sandbox Code Playgroud)
我想使用泛型,所以我不必为此分别使用Int,Float,Double制作3个副本
但这是行不通的,我认为泛型真的很难使用,请帮助我:)
我正在尝试Jetpack Navigation component并设置了一个非常基本的导航图,其中只有 2 个片段,其中一个主片段 ( Foo) 包含一个按钮,该按钮调用导航操作以打开另一个片段 ( Bar)。
仅使用基本的 Android 用法和功能就可以按预期工作,我可以Foo通过按后退按钮导航回并Bar再次向前导航。
我实现了这个方便的delegate类,以我喜欢的方式通过 id 绑定视图(我最初是一个 iOS 开发者)。
class FindViewById<in R, T: View>(private val id: Int) {
private var view: T? = null
operator fun getValue(thisRef: R, property: KProperty<*>): T {
var view = this.view
if (view == null) {
view = when (thisRef) {
is Activity -> thisRef.findViewById(id)!!
is Fragment -> thisRef.requireView().findViewById(id)!!
is View -> thisRef.findViewById(id)!!
else -> throw …Run Code Online (Sandbox Code Playgroud) android android-fragments kotlin android-jetpack android-architecture-navigation
ios ×5
android ×3
swift ×3
generics ×2
java ×2
android-architecture-navigation ×1
arrays ×1
audio ×1
autolayout ×1
avfoundation ×1
camera ×1
camera2 ×1
email ×1
gmail ×1
json ×1
kotlin ×1
nsdictionary ×1
operators ×1
retrofit ×1
robospice ×1
smtp ×1
sprite-kit ×1
uiview ×1
vb.net ×1