我正在使用UISplitViewController构建一个通用应用程序,并针对iOS 9及更高版本.应用语言是Objective-C.
开始使用Xcode Master/Detail模板并以标准方式设置我的视图后,我意识到如果我一直在屏幕上保持主视图(在iPad上),应用程序会更好,包括当设备是在纵向模式下.然而,无论我搜索多么努力,我找不到任何东西来帮助我了解这是如何实现的.我知道这是以前使用splitViewController实现的:shouldHideViewController:inOrientation:
但是,在iOS 9中不推荐使用此方法,我无法弄清楚替换它的原因以及原因.我已经查看了UISplitViewController的新委托方法,发现它们完全没有任何直观性.
我非常感谢有关替换splitViewController的一些指示:shouldHideViewController:inOrientation:以及它如何用于在iPad上始终显示主视图.
我正在尝试将UICollectionView显示在一个模态显示的视图控制器中.该应用适用于iPad iOS 7.
我已经创建了UIViewController的子类(带有一个nib),并添加如下:
MyViewController *controller = [[MyViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
navController.modalPresentationStyle = UIModalPresentationFullScreen;
navController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[self presentViewController:navController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
这个视图控制器是我的UICollectionView的委托和dataSource所以我已经将UICollectionViewDataSource和UICollectionViewDelegate添加到标头中.
我将一个UICollectionView放入nib并为MyViewController添加了一个插座:
@property (strong, nonatomic) IBOutlet MyCollectionView *collectionViewController;
Run Code Online (Sandbox Code Playgroud)
我在MyViewController的viewDidLoad中添加了这个:
self.collectionViewController.dataSource = self;
self.collectionViewController.delegate = self;
Run Code Online (Sandbox Code Playgroud)
我还在MyViewController中添加了以下内容:
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
NSLog(@"Items in section: %d", itemsArray.count); // returns correct amount
return itemsArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"cellForItemAtIndexPath %@", indexPath); // returns as expected
static NSString *identifier = @"MyCell";
[self.collectionViewController registerClass:[MyCollectionCell …Run Code Online (Sandbox Code Playgroud) ipad ios uicollectionview uicollectionviewcell uicollectionviewlayout
我有一个iPad应用程序,它使用UISplitViewController(左侧是UITableView,右侧是详细视图).点击它时,我的表格视图会以蓝色突出显示所选单元格.
当我调用以下方法时,单元格被选中但不以蓝色突出显示:
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop];
Run Code Online (Sandbox Code Playgroud)
我花了很多时间来处理各种委托方法和黑客试图让单元格以编程方式突出显示,就好像它已被挖掘一样.我不能这样做.
我已经设法几乎到达那里:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (shouldHighlightCell)
{
NSIndexPath *indexPathForCellToHighlight = [NSIndexPath indexPathForRow:0 inSection:0];
if ([indexPath isEqual:indexPathForCellToHighlight])
{
cell.selected = YES;
shouldHighlightCell = NO;
}
}
}
Run Code Online (Sandbox Code Playgroud)
只要我也有这个功能,它就可以正常工作(否则即使在点击另一个单元时它仍保持选中状态):
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSIndexPath *ip = [NSIndexPath indexPathForRow:0 inSection:0];
if ([[self.tableView cellForRowAtIndexPath:ip] isSelected])
{
[[self.tableView cellForRowAtIndexPath:ip] setSelected:NO];
}
NSIndexPath *iToTheP = indexPath;
return iToTheP;
}
Run Code Online (Sandbox Code Playgroud)
我知道这是一个奇怪而复杂的解决方法.我不介意,但它甚至没有完全发挥作用.如果选定的单元格在屏幕上滚动,则会丢失其突出显示,而在屏幕上滚动时,已点击的单元格仍会突出显示.
我对这一点感到非常困惑.我确信这种解决方法甚至不是必需的,有一个更简单的解决方案.
我正在使用UIScrollView,它可以在任一方向使用并包含许多子视图:
// in viewDidLoad
mainScrollView = (UIScrollView *)self.view;
mainScrollView.contentSize = CGSizeMake(1024, 1432);
Run Code Online (Sandbox Code Playgroud)
我正在尝试捕获整个滚动视图的屏幕截图及其所有子视图,包括屏幕上当前不可见的内容.以下内容仅捕获捕获时屏幕上可见的内容:
// make screenshot
UIGraphicsBeginImageContext(mainScrollView.bounds.size);
[mainScrollView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// save screenshot in docs dir
NSData *pngData = UIImagePNGRepresentation(screenImg);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
[pngData writeToFile:[documentsDir stringByAppendingPathComponent:@"screen1.png"]
options:NSDataWritingAtomic error:nil];
Run Code Online (Sandbox Code Playgroud)
在进行屏幕截图之前添加以下内容是我唯一能让我捕获整个滚动视图的方法:
// capture off-screen content
mainScrollView.frame = CGRectMake(0, 0, 1024, 1432);
Run Code Online (Sandbox Code Playgroud)
此捕获很好,包括所有子视图.问题是,一旦我进行了屏幕截图,我的滚动视图就会变得无法响应,因此我无法再滚动(或者如果处于纵向模式,则横向平移).如果我旋转设备,问题似乎纠正自己,我可以正常滚动和平移.我确定我错过了一些非常简单的东西,以便在拍摄屏幕截图后让我的滚动视图正常工作.任何建议非常感谢!
我正在尝试在 iOS 中绘制四分之一圆。在 Mac OS 中,您似乎可以使用 appendBezierPathWithArcWithCenter 但这似乎不适用于 iOS。
有谁知道如何在 iOS 中简单地绘制四分之一圆?
谢谢
我知道有几次问过类似的问题,但是我很难理解这个特殊问题是如何解决的.到目前为止,我所做的一切都是在主要方面进行的.我现在发现我需要执行一个需要一些时间的操作,并且我希望在操作期间向我的显示器添加HUD并在操作完成时将其淡出.
在阅读了很多关于GCD(并且变得非常困惑)之后,我决定最简单的方法是使用NSInvocationOperation调用我耗时的方法并将其添加到新创建的NSOperationQueue中.这就是我所拥有的:
[self showLoadingConfirmation]; // puts HUD on screen
// this bit takes a while to draw a large number of dots on a MKMapView
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(timeConsumingOperation:)
object:[self lotsOfDataFromManagedObject]];
// this fades the HUD away and removes it from the superview
[operation setCompletionBlock:^{ [self performSelectorOnMainThread:@selector(fadeConfirmation:) withObject:loadingView waitUntilDone:YES]; }];
NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];
[operationQueue addOperation:operation];
Run Code Online (Sandbox Code Playgroud)
我希望这能显示HUD,开始在地图上绘制点,然后一旦完成该操作,就会消除HUD.
相反,它显示HUD,开始在地图上绘制点,并在仍然绘制点的同时淡化HUD.根据我的NSLogs,在调用淡入HUD的方法之前,有大约四分之一秒的延迟.与此同时,点的绘制持续了几秒钟.
我可以做些什么让它等到地图上的绘图完成后才会消失HUD?
谢谢
编辑添加:
在进行以下更改后,我几乎成功了:
NSInvocationOperation *showHud = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(showLoadingConfirmation)
object:nil];
NSInvocationOperation *operation = …Run Code Online (Sandbox Code Playgroud) nsoperation nsoperationqueue nsinvocation ios nsinvocationoperation
我有一个应用程序,用于CLLocationManager跟踪用户的路线,沿着所采取的路径绘制点.该应用程序在后台使用必需的后台模式>应用程序寄存器进行位置更新.
据我所知,后台发生的任何事情都需要调用,locationManager:didUpdateToLocation:fromLocation因为这是每个位置更新调用的方法.
我遇到的问题是有时会停止调用.当用户的位置在大约15分钟左右的时间内没有太大变化时,似乎会发生这种情况.据我所知,调用locationManager:didUpdateToLocation:fromLocation只是停止,大概是为了节省电池.不幸的是,当你回到移动状态时,它不会再次恢复.
我认为无法覆盖此行为,因此我想使用通知中心通知用户应用程序不再记录路由.问题是,应用程序如何知道发生了这种情况?如果未调用locationManager:didUpdateToLocation:fromLocation,则无法触发我的通知.如果正在调用它,则不应触发通知.
是否有某种系统通知表明位置更新将停止?
我发现很难调试这个,因为当我出去测试设备上的位置时,我无法随身携带我的Mac(在模拟器中你只能做很多事情).任何调试技巧也将非常感谢!
我在Sprite Kit中使用碰撞检测.它正在工作并阻止我的精灵穿越路径.但是,我没有在didBeginContact中收到通知:我似乎无法控制物理引擎在发生碰撞时如何响应.
我有各种汽车(SKSpriteNodes)使用SKAction followPath在以下路径中移动:asOffset:orientToPath:duration:
以前,如果两辆车越过小路,他们都会像往常一样继续前行,一辆车越过另一辆.为了实现碰撞检测,我做了以下更改......
将此添加到我的@interface:
<SKPhysicsContactDelegate>
Run Code Online (Sandbox Code Playgroud)
将此添加到我的@implementation中:
static const uint32_t carCategory = 0x1 << 0;
Run Code Online (Sandbox Code Playgroud)
在我的init方法中添加了这个:
self.physicsWorld.contactDelegate = self;
self.physicsWorld.gravity = CGVectorMake(0.0, 0.0);
Run Code Online (Sandbox Code Playgroud)
我创造了我的蓝色汽车:
- (void)addBlueCar
{
_blueCar = [SKSpriteNode spriteNodeWithImageNamed:@"Blue Car.png"];
_blueCar.position = CGPointMake(818.0, -50.0);
_blueCar.name = @"car";
[self addChild:_blueCar];
CGSize contactSize = CGSizeMake(_blueCar.size.width - 5.0, _blueCar.size.height - 5.0);
_blueCar.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:contactSize];
_blueCar.physicsBody.categoryBitMask = carCategory;
_blueCar.physicsBody.collisionBitMask = carCategory;
_blueCar.physicsBody.contactTestBitMask = carCategory;
}
Run Code Online (Sandbox Code Playgroud)
我还创造了一辆红色汽车:
- (void)addRedCar
{
_redCar = [SKSpriteNode spriteNodeWithImageNamed:@"Red Car.png"];
_redCar = CGPointMake(818.0, -50.0);
_redCar = …Run Code Online (Sandbox Code Playgroud) ios ×8
ipad ×4
objective-c ×3
bezier ×1
cllocation ×1
ios9 ×1
iphone ×1
nsbezierpath ×1
nsinvocation ×1
nsoperation ×1
skspritenode ×1
sprite-kit ×1
uiscrollview ×1
uitableview ×1