Tag: 目标

计算可变参数的移动平均值

我有一个整数属性,每秒更新信号强度值范围从0 – 100。 我希望能够在过去的10,25,50次测量中保持移动平均的持续测量。 什么是最有效的方法呢? 我目前正在考虑使用NSMutableArray来实现一组FIFO队列,并在每次添加一个新的队列时popup前导值,一旦该arrays具有必要的条目数量。 但是,我不确定是否有一个更有效的方法来做到这一点。

如何创build一个可以从不同的视图控制器访问的NSMutable数组

林iPhone相当新的发展,我想创build一个可变的数组,可以访问和从不同的视图控制器填充 。 我该怎么做? 如果你可以请给我一个示例代码

在iOS中自定义“可resize的图像”

UIImage API提供了调整图像大小的方法,其中某些区域被拉伸,而其他区域保持不变 – 非常适合可resize的UI元素的背景图像。 现在我正在寻找一种方法来为更复杂的背景图像定制这种行为。 这是什么- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets; 确实。 透明区域保持不变,当视图大小改变时红色区域被拉伸。 这就是我想要的 – 对延伸的区域进行更细粒度的控制: 我想我必须通过覆盖我的UIView子类的-(void)drawRect:方法,然后使用Quartz来完成图像的绘制。 我只是不知道我将不得不使用哪个系统API。 有谁能给我一个提示如何做到这一点? 提前致谢!

setSelectedImageTintColor在iOS 7中不起作用

我想在iOS 7中设置setSelectedImageTintColor ,但它不工作。 这是我在我的AppDelegate.m下的didFinishLaunchingWithOptions的代码 UITabBarController *tabBarController = (UITabBarController *) self.window.rootViewController; UITabBar *tabBar = tabBarController.tabBar; for (UITabBarItem *item in tabBar.items) { UIImage *image = item.image; UIImage *correctImage = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; item.image = correctImage; } [[UITabBar appearance] setTintColor:[UIColor whiteColor]]; [[UITabBar appearance] setSelectedImageTintColor:[UIColor colorWithRed:44.0/255.0 green:176.0/255.0 blue:28.0/255.0 alpha:1.0]]; [[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:51.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:1.0]]; 它仍然不会显示selectedImageTintColor。 选中时是白色的; 灰色时,未选中。 我究竟做错了什么?

IOS:将string转换为hex数组

我有string表示数据。我需要将这些数据转换为hex数组。通过使用hex数组我可以将其传递到CRC写入外设 我的string数据是这样的 NSString *stringsdata=@"helloworld1234567812345q"; 我需要转换为hex格式数组 {0x0h,0x0e…………0x0q}. 所以通过使用这个数组我可以保留在crc中的数据,并将其写入到外围数据 Byte comm[24]; comm[0]=0x01; comm[1]=0x30; comm[2]=0x62; comm[3]=0x00;……………. 已经尝试了许多可能的解决scheme,但不幸运。任何身体的帮助将不胜感激。

缩小pdf大小 – 目标c

我有一个PDF生成项目,它包含一些文本和一个已经存储在数据库中的图像,我想要预览和邮件生成的PDF,只有文本数据时,一切都可以。 如果我们的数据中有图像,就会出现问题。 即使有大小为1MB或以下的图片,邮件也会收到10MB或以上的pdf。在模拟器中工作正常。绘制图像的代码如下所示: UIImage *plotImage=[[UIImage alloc]initWithContentsOfFile:[localPictureArray objectAtIndex:i]]; CGSize imageSize=plotImage.size; CGFloat scaleFactor = 1.0; if (imageSize.height>(maxHeight-currentPageY) || imageSize.width>maxWidth ) { UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, kDefaultPageWidth, kDefaultPageHeight), nil); currentPageY = kMargin; if (!((scaleFactor = (maxWidth / imageSize.width)) > ((maxHeight-currentPageY) / imageSize.height))) { scaleFactor = (maxHeight-currentPageY) /imageSize.height; // scale to fit heigth. } CGRect rect = CGRectMake(kMargin,currentPageY, imageSize.width * scaleFactor, […]

使用AVCaptureAudioDataOutputSampleDelegate无法播放通过语音录制的audio

我一直在Google上search和研究,但我似乎无法得到这个工作,我无法find任何解决scheme,在互联网上。 我试图用麦克风捕捉我的声音,然后通过扬声器播放。 这是我的代码: class ViewController: UIViewController, AVAudioRecorderDelegate, AVCaptureAudioDataOutputSampleBufferDelegate { var recordingSession: AVAudioSession! var audioRecorder: AVAudioRecorder! var captureSession: AVCaptureSession! var microphone: AVCaptureDevice! var inputDevice: AVCaptureDeviceInput! var outputDevice: AVCaptureAudioDataOutput! override func viewDidLoad() { super.viewDidLoad() recordingSession = AVAudioSession.sharedInstance() do{ try recordingSession.setCategory(AVAudioSessionCategoryPlayAndRecord) try recordingSession.setMode(AVAudioSessionModeVoiceChat) try recordingSession.setPreferredSampleRate(44000.00) try recordingSession.setPreferredIOBufferDuration(0.2) try recordingSession.setActive(true) recordingSession.requestRecordPermission() { [unowned self] (allowed: Bool) -> Void in […]

AVCaptureTorchModeAuto不会持续更新火炬模式

我正在写一个应用程序,根据照明条件自动打开iOS设备背面的手电筒。 该应用呈现实时相机视图,并且不loggingvideo。 我曾尝试使用AVCaptureTorchModeAuto ,但它似乎只是在拍摄会话开始时测量图像的亮度,并相应地设置了手电筒。 然后,不pipe摄像机图像的亮度如何,设置都不会改变。 如文件中所述 ,系统可以持续调整割炬吗? 捕捉设备持续监控光照水平,并在必要时使用手电筒。 在iOS 4.0及更高版本中可用。

用UIButton作为CustomView的UIBarButtonItem – 从UIButton,如何访问UIBarButtonItem它的in?

我有一个UIBarButtonItem与UIButton作为自定义视图。 UIButton有一个addTarget:action:就可以了。 在行动中,我提出了一个popover。 我目前从sender.frame ( UIButton的框架),我想从UIBarButtonItem代替。 我如何从UIButton访问UIBarButtonItem ?

如何在AVMutableComposition中使用scaleTimeRange?

我有一个关于在AVMutableComposition中缩放video长度的问题,以加快或减慢它的速度。 我知道这样做的代码是 scaleTimeRange:(CMTimeRange)timeRange toDuration:(CMTime)duration 问题是我不知道如何使用该代码。 我目前对我的作品有一个录制的video轨道和一个音轨提供。 有人可以告诉我如何添加这个来让我的video加速或减速? 这是我的代码: AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:audioURL options:nil]; AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:videoURL options:nil]; AVMutableComposition* mixComposition = [AVMutableComposition composition]; AVMutableCompositionTrack *compositionCommentaryTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; [compositionCommentaryTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:kCMTimeZero error:nil]; AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:kCMTimeZero error:nil]; AVAssetExportSession* _assetExport […]