我正在使用Photos框架(又名PhotoKit).在我的应用程序中,我需要收集Moments(属于类型PHAssetCollection).PHAssetCollection有一个属性CLLocation *approximateLocation.
但是NSPredicate当我从PhotoKit检索Moments时,我无法工作.
-(void)getMomentsNearCoordinate:(CLLocationCoordinate2D)coordinate completionBlock:(PKAssetManagerArrayBlock)completionBlock{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.predicate = [NSPredicate predicateWithFormat:@"approximateLocation.coordinate.latitude < 37.0"];
self.moments = [PHAssetCollection fetchMomentsWithOptions:options];
// Convert PHCollection into NSArray
NSMutableArray *momentsArray = [[NSMutableArray alloc]initWithCapacity:self.moments.count];
[self.moments enumerateObjectsUsingBlock:^(PHAssetCollection *moment, NSUInteger idx, BOOL *stop) {
[momentsArray addObject:moment];
}];
dispatch_async(dispatch_get_main_queue(), ^{
completionBlock([NSArray arrayWithArray:momentsArray]);
});
});
}
Run Code Online (Sandbox Code Playgroud)
调试器将停止运行
self.moments = [PHAssetCollection fetchMomentsWithOptions:options];
Run Code Online (Sandbox Code Playgroud)
有错误:
***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'获取选项中不支持的谓词:approximateLocation.coordinate.latitude <37'
这似乎很奇怪,因为我可以使用或NSPredicate过滤.startDateendDate
无论如何,接下来我以为我会尝试使用NSPredicatewith块:
-(void)getMomentsNearCoordinate:(CLLocationCoordinate2D)coordinate completionBlock:(PKAssetManagerArrayBlock)completionBlock{ …Run Code Online (Sandbox Code Playgroud) 我希望将我的一些 CoreBluetooth 代码从 iOS 移植到 OS X。我已经设置了一组共享的 CoreBluetooth 包装器,iOS 应用程序和 OS X 应用程序使用相同的 BLE 设备以完全相同的方式使用这些包装器.
外围设备扫描:
override init() {
super.init()
let queue = DispatchQueue.global(qos: .background)
centralManager = CBCentralManager(delegate: self, queue: queue)
}
func startScanning() {
let options: [String: Any] = [CBCentralManagerScanOptionAllowDuplicatesKey: true]
let deviceUUID = CBUUID(string: Project.Service.Device)
let recoveryUUID = CBUUID(string: Project.Service.DFURecovery)
centralManager?.scanForPeripherals(withServices: [deviceUUID, recoveryUUID], options: options)
}
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber){
// Inspect advertisementData here to decipher what kind …Run Code Online (Sandbox Code Playgroud) bluetooth core-bluetooth bluetooth-lowenergy cbperipheral cbcentralmanager
假设标准配置(向上/向下),我想检测用户何时UIColletionView向上或向下滚动(这是子类UIScrollView和符合的类型UIScrollViewDelegate).我没有看到代表直接发现任何信息来检测这一点,尽管我可能已经在寻找一些东西了.
如果我知道用户正在滚动的方向,那么我可以使用这些UICollectionViewDatasource方法来确定是否应该从REST服务器加载更多数据,或者清除我已经拥有的用于管理固定内存空间的信息.
//如果向下滚动,则显示部分
- (UICollectionReusableView *)collectionView:(UICollectionView *)cv viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
Run Code Online (Sandbox Code Playgroud)
//如果向下滚动,则节中的最后一个单元格正在消失
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
Run Code Online (Sandbox Code Playgroud)
//如果向上滚动,则显示部分中的最后一个单元格
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
Run Code Online (Sandbox Code Playgroud)
//如果向上滚动,部分就会消失
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingSupplementaryView:(UICollectionReusableView *)view forElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath{
Run Code Online (Sandbox Code Playgroud) 我已UIActivityViewController在我的应用程序中实现,可以成功共享字符串和图像.但是,我注意到当您在iOS照片应用程序中共享图像时,有些服务没有出现在我的应用程序中.即打印,用作壁纸,分配给联系人和照片流.我的应用程序能够使用邮件,消息,Facebook,Twitter和复制就好.
我想的是:
1)作为照片应用程序内的定制服务使用这些额外的服务已经实现UIActivityItemProvider,UIActivityItemSource等等.
2.)我提供的数据格式不正确,无法与这些服务一起使用.
我已经通过文件几次读取,但似乎并没有看到任何关于它.
编辑:按要求显示代码:
#define SM_SHARE_IMAGE_AND_STRING 1
-(void)actionToolbarViewControllerUserTappedShareButton:(SMActionToolbarViewController*)sender{
// Reposition anchor view for UIPopoverController to point at
[self repositionAnchorViewToButtonFrame:self.actionToolbarViewController.shareButtonFrame];
// Asynch download of image
[SMUtility downloadAsset:self.selectedAsset completion:^(UIImage *image) {
// Create image source
SMActivitySource *activityImageSource = [[SMActivitySource alloc]initWithImage:image];
#if defined(SM_SHARE_IMAGE_AND_STRING)
// Create string source
NSString *assetsString = [SMUtility assetsString:[NSArray arrayWithObject:self.selectedAsset]];
SMActivitySource *activityStringSource = [[SMActivitySource alloc]initWithString:assetsString];
// Present UIActiviyViewController within an UIPopoverController
NSArray *items = [@[activityImageSource, activityStringSource]mutableCopy];
#else
NSArray *items = [@[activityImageSource]mutableCopy];
#endif …Run Code Online (Sandbox Code Playgroud) 我希望的是MKMapView继承UIScrollView就像UITableView和UICollectionView是.这样,您可以覆盖UIScrollView委托方法并执行您需要执行的操作.
我找到了将平移手势附加到MapView类似的方法,所以:
UIPanGestureRecognizer* mapPanGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(mapPanGestureHandler:)];
[mapPanGestureRecognizer setDelegate:self];
[self.mapView addGestureRecognizer:mapPanGestureRecognizer];
Run Code Online (Sandbox Code Playgroud)
除了mapView具有减速元件的事实之外,这相当好.例如,如果您处于中间滚动并抬起手指,地图会继续前进并减速然后最终停止.
我正在做的是UIView使用核心图形在我的地图(另一个)顶部的叠加层中渲染一些屏幕外注释.除减速问题外,它工作得很好.
我需要知道的是地图已经移动了.我需要的参数我可以直接从地图本身查询.
有没有人找到一种技术来减速时获得回调?我的意思是我想我可以在手势结束时重复射击半秒钟左右使用计时器.
使用我的6+我一直在尝试使用CoreMotion的新CMAltimeter读取相对高度和压力.然而,回调永远不会解雇.我有一个非常相似的设置,而是使用加速度计,陀螺仪和磁力计.他们似乎都很好.
想知道是否有人设法获得阅读?
- (void)viewDidLoad {
[super viewDidLoad];
if([CMAltimeter isRelativeAltitudeAvailable]){
CMAltimeter *altimeterManager = [[CMAltimeter alloc]init];
[altimeterManager startRelativeAltitudeUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMAltitudeData *altitudeData, NSError *error) {
// This never fires.
NSString *data = [NSString stringWithFormat:@"Altitude: %f %f", altitudeData.relativeAltitude.floatValue, altitudeData.pressure.floatValue];
NSLog(@"%@", data);
self.altimeterLabel.text = data;
}];
NSLog(@"Started altimeter");
self.altimeterLabel.text = @"-\n-";
} else {
NSLog(@"Altimeter not available");
}
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过快速步行,但是这里只有一个高度失去/获得的故事.
我在这里错过了什么?我认为^是一个智能指针,我可以通过ref将字符串传递给函数.其他帽子物品怎么样?
// calling code
MyClass::GetString(_str1, _str2);
// both strings are nullptr at this point
/* static */
MyClass::GetStrings(String^ str1, String^ str2)
{
// Read from Local Settings
auto value = localSettings->Values->Lookup(kKey);
String^ temp = ref new String(value->ToString()->Data());
str1 = temp;
// same for str2
}
Run Code Online (Sandbox Code Playgroud) 我非常希望看到你可以用Xcode 6中的SKS编辑器做的所有事情.我能够在sks编辑器中布置一些精灵,灯光,法线等等.然后我可以在我的视图控制器中加载sks文件,如下所示:
-(void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
// Configure the view.
SKView * skView = (SKView *)self.view;
if (!skView.scene) {
skView.showsFPS = YES;
skView.showsNodeCount = YES;
NSString *scenePath = [[NSBundle mainBundle] pathForResource:@"MyScene" ofType:@"sks"];
SKScene *scene = [NSKeyedUnarchiver unarchiveObjectWithFile:scenePath];
[skView presentScene:scene];
self.scene = scene;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我没有看到如何将任何代码绑定到sks文件.例如,我有MyScene.sks(名为MyScene).然后我创建了类文件MyScene.h和MyScene.m,以便我可以以编程方式控制场景.但是,当我放置断点MyScene.m时,它们都没有到达.
如何将MyScene.h/m绑定到MyScene.sks?
问这个问题的另一种方式.在MyScene.sks中,我有一个背景纹理(在编辑器中命名为背景)和一个灯(在编辑器中命名为light1).我想以编程方式移动光线.我希望我能够创建MyScene.h/m,覆盖touchesBegan/touchesMoved,并调整灯光的位置.当我添加此代码时,它从未执行过.为什么?
ios ×6
iphone ×2
bluetooth ×1
c++-cx ×1
cbperipheral ×1
ckquery ×1
cmaltimeter ×1
core-motion ×1
ios8 ×1
ipad ×1
mapkit ×1
nspredicate ×1
photokit ×1
scenekit ×1
sprite-kit ×1
uiview ×1
visual-c++ ×1
xcode6 ×1