我有UICollectionView水平滚动,并且每个屏幕总共有2个单元格并排.我需要滚动才能在单元格的开头停止.启用分页后,集合视图会滚动整个页面,一次是2个单元格,然后停止.
我需要启用单个单元格的滚动,或者在单元格的边缘停止滚动多个单元格.
我试图子类化UICollectionViewFlowLayout并实现该方法targetContentOffsetForProposedContentOffset,但到目前为止我只能破坏我的集合视图并停止滚动.有没有更简单的方法来实现这个以及如何,或者我真的需要实现UICollectionViewFlowLayout子类的所有方法?谢谢.
我需要经常隐藏和取消隐藏导航器和检查员,以便为Interface Builder和复杂的故事板腾出空间.我在Xcode中学习了窗格中的所有显示/隐藏快捷方式,但找不到任何用于显示和隐藏文档大纲的内容.有没有办法在键盘上实现这一点?
下面的代码滚动到右边的单元格UICollectionView,但UINavigationBar在我的情况下隐藏了部分标题视图.我相信我应该使用scrollRectToVisible而我的问题是,CGRect当numberOfRows给定section的变量时,计算(y位置)的正确方法是什么.
- (void)scrollToPricing:(NSUInteger)row {
[self.collectionView scrollToItemAtIndexPath:
[NSIndexPath indexPathForItem:0
inSection:row]
atScrollPosition:UICollectionViewScrollPositionTop
animated:YES];
}
Run Code Online (Sandbox Code Playgroud) 我有自定义UITableViewCell和管理我的细胞选择.选择单元格并显示复选标记后,单元格Content View宽度会缩小,带有尾随约束的标签会向左移动.如何有效避免内容移动?
我不想将约束设置为前导,因为我具有灵活的tableview宽度并且它们是右对齐的.当我想通过更新代码标签的限制它的IBOutlets我走进了麻烦,因为我返回的多个子类UITableViewCell中cellForRow:,我得到了中无法识别的选择错误didSelectRowAtIndexPath:尝试在代码中设置的限制时.任何优雅的解决方 谢谢.


我在第一个选项卡上有基于UITabBarController的iPad应用程序和containerView.containerView具有标准垂直间距到底部布局指南.当我点击第二个标签然后返回第一个标签时,我的容器向下移动56点,tabBar的高度然后被tabBar覆盖.
我做了3个截图来说明这一点.第三个屏幕截图显示了选项卡之间跳转后隐藏的tabBar.看起来底部布局指南落到了边缘.这里发生了什么?

我现在正在努力解决这个问题,到目前为止Apple的文档和SO都没有帮助.我在UIManagedDocument上使用ManagedObjectContext,下面的代码运行正常.然后我决定在AppDelegate中使用Apple的CoreData模板,因此在AppDelegate中创建了模型,持久性存储协调器和上下文.使用AppDelegate的上下文获取是没有问题的,但是后台保存是一个问题.我应该在我保存的线程上有本地上下文,并且根据Apple有相同的持久性存储协调器.但是下面的代码实际上并没有保存数据.请问有人可以提供建议吗?谢谢.
- (void)fetchAndPersist
{
dispatch_queue_t ffetchQ = dispatch_queue_create("ForFetch", NULL);
dispatch_async(ffetchQ, ^{
NSManagedObjectContext *secureManagedObjectContext;
NSPersistentStoreCoordinator *coordinator = [appDelegate persistentStoreCoordinator];
if (coordinator != nil) {
secureManagedObjectContext = [[NSManagedObjectContext alloc] init];
[secureManagedObjectContext setPersistentStoreCoordinator:coordinator];
}
// find missing date
DataManager *dataManager = [[DataManager alloc] init];
NSDate *missingDate = [dataManager findMissingDateFromDate:selectedDate inContext:secureManagedObjectContext];
if (missingDate) {
// fetch and parse data
DataFetcher *dataFetcher = [[dataFetcher alloc] init];
NSDictionary *fetchResponse = [dataFetcher parseDataForDate:missingDate];
// persist it in a block and wait for it
[secureManagedObjectContext performBlock:^{
DataStore *dataStore …Run Code Online (Sandbox Code Playgroud) 我们有通过bitmovin.com编码的视频,并以HTTP Live Streams(Fairplay HLS)的形式提供,但字幕虽然是WebVTT格式,但是作为整个文件的直接URL单独公开,而不是单个段,并且不是HLS m3u8播放列表的一部分.
我正在寻找单独下载的外部.vtt文件如何仍然包含在HLS流中并作为AVPlayer中的副标题提供的方式.
我知道Apple的建议是将分段的VTT字幕包含在HLS播放列表中,但我现在无法改变服务器实现,所以我想澄清是否有可能为AVPlayer提供字幕以与HLS流一起播放.
关于这个主题的唯一有效帖子声称它是可能的:AVPlayer/MPMoviePlayerController的字幕.但是,示例代码从bundle加载本地mp4文件,我正在努力使其适用于m3u8播放列表AVURLAsset.实际上,我有问题从远程m3u8流中获取videoTrack作为asset.tracks(withMediaType: AVMediaTypeVideo)返回空数组.任何想法,如果这种方法可以用于真正的HLS流?或者有没有其他方法可以使用HLS流播放单独的WebVTT字幕,而不将它们包含在服务器上的HLS播放列表中?谢谢.
func playFpsVideo(with asset: AVURLAsset, at context: UIViewController) {
let composition = AVMutableComposition()
// Video
let videoTrack = composition.addMutableTrack(withMediaType: AVMediaTypeVideo, preferredTrackID: kCMPersistentTrackID_Invalid)
do {
let tracks = asset.tracks(withMediaType: AVMediaTypeVideo)
// ==> The code breaks here, tracks is an empty array
guard let track = tracks.first else {
Log.error("Can't get first video track")
return
}
try videoTrack.insertTimeRange(CMTimeRangeMake(kCMTimeZero, asset.duration), of: track, at: kCMTimeZero)
} catch {
Log.error(error)
return …Run Code Online (Sandbox Code Playgroud) 我继承了从Web服务解析并填写的代码NSDictionary.在我将要探索的某些情况下,解析器返回的NSDictionary计数为5,但对象无效.发送给它们的任何消息都会因无法识别的选择器而isKindOfClass:失败.
当我圃在控制台中的对象,我看到这一点:
error: Execution was interrupted, reason: Attempted to dereference an invalid
ObjC Object or send it an unrecognized selector.
The process has been returned to the state before expression evaluation.
Run Code Online (Sandbox Code Playgroud)
如果isKindOfClass:在这里不起作用,我如何检查对象是否无效?
这是崩溃期间控制台的输出.你看到有5个空对象的字典,对象9上的po返回无效消息.

这是大词典的po:

我希望我能够在解析器中检查问题,但我也对如何检查该无效对象以防止崩溃感兴趣.
我正在使用具有content-available:true标志的远程通知,以在无提示推送通知时在后台启动应用程序,并处理或从远程API获取更新。当应用程序处于前台状态或上次运行后处于挂起状态时,代码可以正常执行。
在后台测试期间,当系统根据传入的静默推送通知启动应用程序时,仅对代码进行了部分处理,并且在大约150毫秒后迅速将其挂起。我希望该应用程序将有30秒的时间来处理传入的通知及其有效负载。如果需要更多时间来处理和/或获取新数据,是否需要调整应用程序功能或请求后台任务?
部署目标iOS 8,在iOS 9上进行测试.Xcode 7.3.1,Swift 2.2.1。
功能:启用后台模式,模式:启用远程通知
AppDelegate
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
if let userInfo = userInfo as? [String: AnyObject] {
// Processing of the payload is done in separate Operation class (using Operations framework)
// The completion handler is called on the end of the processing/fetching in that operation
// But in case of launching the app in the background it never reaches the call of the completion …Run Code Online (Sandbox Code Playgroud) 如果您在行动画期间不断旋转设备,此示例应用程序将在一段时间后崩溃.即使在行动画中的第一次旋转,我的真实应用程序也会崩溃.
我应该如何保护我的应用程序在旋转期间与同时行动画一起崩溃?在动画完成之前,请不要建议禁止轮换.DataSource依赖于网络提取,根据用户网络可能需要1到30秒,如果用户希望在启动后立即更好地查看应用程序,则用户想要旋转设备.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
for (int i = 0; i < 30; i++) {
[NSThread sleepForTimeInterval:0.2]; // imitates fetching and parsing
[self.array addObject:[NSString stringWithFormat:@"cell number %d", i]];
dispatch_async(dispatch_get_main_queue(), ^{
// perform on main
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
});
}
});
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
// Configure the …Run Code Online (Sandbox Code Playgroud) 我需要更新Enum存储在中的关联值Array。如何在不知道其索引的情况下访问适当大小的单元格?
enum MessageCell {
case from(String)
case to(String)
case subject(String)
case body(String)
}
var cells = [MessageCell.from(""), MessageCell.to(""), MessageCell.subject(""), MessageCell.body("")]
let recipient = "John"
// Hardcoded element position, avoid this
cells[1] = .to(recipient)
// How to find the index of .to case
if let index = cells.index(where: ({ ... }) {
cells[index] = .to(recipient)
}
Run Code Online (Sandbox Code Playgroud) 请查看这个UILabel带有 Autolayout的动态多线的简单示例,它应该强制其超级视图增加高度。该示例在纵向模式下运行良好,而在横向模式下UILabel,高度增长过多。
我在故事板中设置了约束,标签的垂直压缩和拥抱优先级是 1000,超级视图的优先级是 1。视图之间的所有其他顶部、底部、前导和尾随约束都是标准的。
我用非常浅的灰色给标签的背景着色,所以很明显标签的顶部和底部边距比纵向模式大得多。有人可以建议我如何在横向中获得具有相同顶部和底部边距的标签吗?谢谢。

- (void)viewDidLoad
{
[super viewDidLoad];
self.myTextLabel.text = @"iPhone 6 rumoured to have larger display.";
}
- (IBAction)button:(UIButton *)sender
{
if (!self.flag) {
self.innerHeightConstraint.constant = 120.0;
self.myTextLabel.text = @"iPhone 6 rumoured to have larger, 1704 x 960 display. A new report indicates that Apple's testing it.";
self.flag = YES;
} else {
self.innerHeightConstraint.constant = 60.0;
self.myTextLabel.text = @"iPhone 6 rumoured to have larger display.";
self.flag = NO;
}
[self.view layoutIfNeeded];
}
Run Code Online (Sandbox Code Playgroud) 当我清除数据源中的所有数据并重新加载tableView时,不再提供pull-to-refresh.如何在空tableView上启用pull-to-refresh?
override func viewDidLoad() {
super.viewDidLoad()
...
// Pull to refresh for iPhone
refreshControl?.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
tableView.tableFooterView = UIView(frame: CGRectZero) // To remove separator line on empty cells
tableView.estimatedRowHeight = Constants.DetailTableView.estimatedRowHeight
tableView.rowHeight = UITableViewAutomaticDimension
setupRefreshControl()
}
private func setupRefreshControl() {
// If on iPhone, List becomes the pull-to-refresh handler and the delegate
if UIScreen.mainScreen().traitCollection.horizontalSizeClass == .Compact {
SyncService.shared.delegate = self
refreshControl?.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
refreshControl?.tintColor = UIColor.whiteColor()
} else {
// Otherwise disable the refresh control in …Run Code Online (Sandbox Code Playgroud) ios ×11
objective-c ×5
autolayout ×3
uitableview ×3
swift ×2
xcode ×2
avfoundation ×1
avkit ×1
avplayer ×1
constraints ×1
core-data ×1
enums ×1
iphone ×1