我想强制用户使用我自己的init方法(例如-(id)initWithString:(NSString*)foo;)而不是基本的[[myObject alloc]init];.
我怎样才能做到这一点?
我有一个 - 我希望 - 非常简单的问题:如何在IOS5中禁用UISearchBar以避免用户交互?我找不到setEnabled或类似的东西......
谢谢!
在Obj-C中,可以通过以下字母迭代字母:
for (char x='A'; x<='Z'; x++) {
Run Code Online (Sandbox Code Playgroud)
在Swift中,这是不可能的.知道我怎么能这样做吗?
我正在使用swift构建我的第一个IOS应用程序,我遇到了问题:如何在流式传输时获取音乐文件的长度(持续时间)?
我做了很多研究,并编写了一些代码来解决这个问题,但似乎我的代码还不够好.
func prepareAudio() {
audioLength = CMTimeGetSeconds(self.player.currentItem.asset.duration)
playerProgressSlider.maximumValue = CFloat(CMTimeGetSeconds(player.currentItem.duration))
playerProgressSlider.minimumValue = 0.0
playerProgressSlider.value = 0.0
showTotalSurahLength()
} // i prepare for get the duration and apply to UISlider here
func showTotalSurahLength(){
calculateSurahLength()
totalLengthOfAudioLabel.text = totalLengthOfAudio
} // get the right total length of audio file
func calculateSurahLength(){
var hour_ = abs(Int(audioLength/3600))
var minute_ = abs(Int((audioLength/60) % 60))
var second_ = abs(Int(audioLength % 60))
var hour = hour_ > 9 ? "\(hour_)" : "0\(hour_)"
var minute = minute_ > …Run Code Online (Sandbox Code Playgroud) 以下是该问题的极为简化的版本:
import UIKit
import CoreMotion
class ViewController: UIViewController {
private let manager = CMMotionManager()
private let interval = 0.01
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
startUpdates()
}
private func startUpdates() {
let queue = OperationQueue()
queue.name = "com.demo.motion"
queue.qualityOfService = .userInteractive
queue.maxConcurrentOperationCount = 1
manager.accelerometerUpdateInterval = interval
manager.startAccelerometerUpdates(to: queue) { _, _ in }
}
}
Run Code Online (Sandbox Code Playgroud)
当我在iPhone XR上运行此程序时,我将收到以下消息:
主线程检查器:在后台线程上调用的UI API:-[UIApplication applicationState] PID:1237,TID:147763,线程名称:com.apple.CoreMotion.MotionThread,队列名称:com.apple.root.default-qos.overcommit ,QoS:0
qualityOfService对此没有影响(我的首选是使用utility)startUpdates()功能包装在主调度程序周围,但没有成功根据队列名称和发生的时间,我认为这是内部的东西,与较旧的设备相比,XR中速度更快的处理器才暴露出来。
我正在使用当前位置图标的自定义调出(标题和副标题).我尝试了以下来禁用默认注释,但它不起作用.
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
NSLog(@"viewForAnnotation");
if ([annotation isKindOfClass:[MKUserLocation class]])
{
MKAnnotationView *userLocationView = [mapView viewForAnnotation:annotation];
userLocationView.canShowCallout = NO;
NSLog(@"[annotation isKindOfClass:[MKUserLocation class]");
return nil;
}
}
Run Code Online (Sandbox Code Playgroud)
只有它的工作方式是
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)ann
{
if([ann.annotation isKindOfClass:[MKUserLocation class]] )
{
[mymap deselectAnnotation:ann.annotation animated:NO];
}
}
Run Code Online (Sandbox Code Playgroud)
但它有时会滞后.是否有其他方法可以禁用当前位置注释的默认标注视图?任何帮助将不胜感激.
给定一个提供的String,如何验证StringSwift中的有效UUID?
一个有效的UUID(据我所知)可能是:
33041937-05b2-464a-98ad-3910cbe0d09e
3304193705b2464a98ad3910cbe0d09e
Run Code Online (Sandbox Code Playgroud) 仍然无法弄清楚我做错了什么.只是试图用里面的导航控制器获得模态视图.
这是我的项目 http://www.matthewpateman.com/New.zip
谁能告诉我我做错了什么?我希望"ShopModalView.xib"能够在导航控制器中弹出,但它只是在空白页面上进行了...
我正在尝试使用AVFoundation在我的iPhone应用程序中录制视频.但每当我单击"录制"按钮时,应用程序都会崩溃
- [AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] - 没有活动/启用的连接.
我知道同样的问题,但是它的答案都没有帮助我.我的问题是相同的代码完全适用于另一个应用程序,当我尝试在这个应用程序中使用完全相同的代码 - 崩溃.但仍然照片捕捉工作正常.
在这里添加我的代码 - 请帮助我,提前致谢
-(void)viewDidLoad
{
[super viewDidLoad];
self.captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
self.videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:nil];
self.audioInput = [[AVCaptureDeviceInput alloc] initWithDevice:audioDevice error:nil];
self.stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *stillImageOutputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
AVVideoCodecJPEG, AVVideoCodecKey, nil];
[self.stillImageOutput setOutputSettings:stillImageOutputSettings];
self.movieOutput = [[AVCaptureMovieFileOutput alloc] init];
[self.captureSession addInput:self.videoInput];
[self.captureSession addOutput:self.stillImageOutput];
previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.captureSession];
UIView *aView = self.view;
previewLayer.frame = CGRectMake(70, 190, 270, …Run Code Online (Sandbox Code Playgroud) 我试图制作一个简单的应用程序,你触摸一个点,一个精灵跟随一条线穿过该点到屏幕的边缘,无论你在哪里触摸.我想绘制连接精灵的原点(它开始的点)和你触摸的点之间的线段,以及精灵的原点和屏幕边缘的终点之间的线段,这样我就可以看到精灵以及原点,触点和终点的x和y偏移之间的关系.
希望这不是太混乱.
TL; DR:我需要在两点之间画一条线,我不知道如何使用SpriteKit Swift.
提前致谢.
ios ×9
objective-c ×4
swift ×4
iphone ×2
xcode ×2
avfoundation ×1
avplayer ×1
core-motion ×1
ios5 ×1
mkannotation ×1
nsobject ×1
sprite-kit ×1
uisearchbar ×1
uuid ×1
video ×1