Google Now 类似于 iOS 上的界面

2024-01-01

所以,我非常喜欢 Android 上的 Google Now 卡片界面。最近它甚至登陆了 iOS。

有没有任何教程或示例项目可以帮助我为我的 iOS 应用程序创建卡片界面?

根据我的研究,我已经能够使用自定义 UICollectionViewFlowLayout 在某种程度上复制“堆叠”卡片。

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
    NSArray *allAttributesInRect = [super layoutAttributesForElementsInRect:rect];

    CGPoint centerPoint = CGPointMake(CGRectGetMidX(self.collectionView.bounds), CGRectGetMidY(self.collectionView.bounds));

    for (UICollectionViewLayoutAttributes *cellAttributes in allAttributesInRect)
    {
        if (CGRectContainsPoint(cellAttributes.frame, centerPoint))
        {
            cellAttributes.transform = CGAffineTransformIdentity;
            cellAttributes.zIndex = 1.0;
        }
        else
        {
            cellAttributes.transform = CGAffineTransformMakeScale(0.75, 0.75);
        }
    }

    return allAttributesInRect;
}

然后我将最小行距设置为负值,使它们看起来“堆叠”。

不过,滚动后,我希望卡片保留在底部,并且只有一辆车可以放大并位于屏幕中央。然后,我将该卡滚动到屏幕外,堆栈中的下一张“卡”将从堆栈中向上滚动并在屏幕上居中。我猜这会动态调整最小行间距?


我认为没有任何教程或课程能够完全满足您的要求。但是,如果您不介意仅针对 iOS6 及更高版本,您可以使用UICollectionView。使用标准的垂直流布局,完成您想要实现的目标应该不难。看一眼:

  • http://developer.apple.com/library/ios/ipad/#documentation/UIKit/Reference/UICollectionView_class/Reference/Reference.html http://developer.apple.com/library/ios/ipad/#documentation/UIKit/Reference/UICollectionView_class/Reference/Reference.html
  • http://www.appcoda.com/ios-programming-uicollectionview-tutorial/ http://www.appcoda.com/ios-programming-uicollectionview-tutorial/
  • http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12 http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12
  • WWDC 2012 第 205 场

我知道这些例子看起来并不完全像你想要实现的目标。但一旦你掌握了基本概念UICollectionView使用这些网站,您将能够立即构建卡片布局。

Update

我创建了一个简单的示例来展示处理单元格“平移”的潜在方法。确保添加必要的代码以从集合视图中删除该项目//Insert code to delete the cell here,然后它将填充您通过删除单元格创建的间隙。

CLCollectionViewCell.h

#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>

@interface CLCollectionViewCell : UICollectionViewCell <UIGestureRecognizerDelegate>

@property (assign, setter = setDeleted:) BOOL isDeleted;
@property (strong) UIPanGestureRecognizer *panGestureRecognizer;

@end

CLCollectionViewCell.m

#import "CLCollectionViewCell.h"

@implementation CLCollectionViewCell

- (id)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super initWithCoder:aDecoder]) {
        // Create a pan gesture recognizer with self set as the delegate and add it the cell
        _panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureRecognizerDidChange:)];
        [_panGestureRecognizer setDelegate:self]; 
        [self addGestureRecognizer:_panGestureRecognizer];
        
        // Don't clip to bounds since we want the content view to be visible outside the bounds of the cell
        [self setClipsToBounds:NO];
        
        // For debugging purposes only: set the color of the content view
        [[self contentView] setBackgroundColor:[UIColor greenColor]];
    }
    return self;
}

- (void)panGestureRecognizerDidChange:(UIPanGestureRecognizer *)panGestureRecognizer {
    if ([self isDeleted]) {
        // The cell should be deleted, leave the state of the cell as it is 
        return;
    }
    
    // Percent holds a float value between -1 and 1 that indicates how much the user moved his finger relative to the width of the cell
    CGFloat percent = [panGestureRecognizer translationInView:self].x / [self frame].size.width;
    
    switch ([panGestureRecognizer state]) {
        case UIGestureRecognizerStateChanged: {
            // Create the 'throw animation' and base its current state on the percent
            CGAffineTransform moveTransform = CGAffineTransformMakeTranslation(percent * [self frame].size.width, 0.f);
            CGAffineTransform rotateTransform = CGAffineTransformMakeRotation(percent * M_PI / 20.f);
            CGAffineTransform transform = CGAffineTransformConcat(moveTransform, rotateTransform) ;
            
            // Apply the transformation to the content view
            [[self contentView] setTransform:transform];
            
            break;
        }
            
        case UIGestureRecognizerStateFailed:
        case UIGestureRecognizerStateEnded:
        case UIGestureRecognizerStateCancelled: {
            // Delete the current cell if the absolute value of the percent is above O.7 or the absolute value of the velocity of the gesture is above 600
            if (fabsf(percent) > 0.7f || fabsf([panGestureRecognizer velocityInView:self].x) > 600.f) {
                // The direction is -1 if the gesture is going left and 1 if it's going right
                CGFloat direction = percent < 0.f ? -1.f : 1.f;
                // Multiply the direction to make sure the content view will be removed entirely from the screen
                direction *= 1.5f;
                
                // Create the transform based on the direction of the gesture
                CGAffineTransform moveTransform = CGAffineTransformMakeTranslation(direction * [self frame].size.width , 0.f);
                CGAffineTransform rotateTransform = CGAffineTransformMakeRotation(direction * M_PI / 20.f);
                CGAffineTransform transform = CGAffineTransformConcat(moveTransform, rotateTransform);
                
                // Calculate the duration of the animation based on the velocity of the pan gesture recognizer and normalize abnormal high and low values
                CGFloat duration = fabsf(1000.f / [panGestureRecognizer velocityInView:self].x);
                duration = duration > 2.f  ? duration = 2.f  : duration;
                duration = duration < 0.2f ? duration = 0.2f : duration;
                
                // Animate the 'throwing away' of the cell and update the collection view once it's completed
                [UIView animateWithDuration:duration
                                 animations:^(){
                                     [[self contentView] setTransform:transform];
                                }
                                 completion:^(BOOL finished){
                                     [self setDeleted:YES];
                                     
                                     // Insert code to delete the cell here
                                     // e.g. [collectionView deleteItemsAtIndexPaths:@[[collectionView indexPathForCell:self]]];
                }];
                
            } else {
                // The cell shouldn't be deleted: animate the content view back to its original position
                [UIView animateWithDuration:1.f animations:^(){
                    [[self contentView] setTransform:CGAffineTransformIdentity];
                }];
            }
            
            break;
        }
            
        default: {
            break;
        }
    }
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    // Return YES to make sure the pan gesture recognizer doesn't interfere with the gesture recognizer of the collection view
    return YES;
}

@end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Google Now 类似于 iOS 上的界面 的相关文章

  • UITextFieldDelegate 与 UITextField 控件事件

    如果我想处理 UITextField 的更改 例如用户在其中键入 看起来这可以通过将委托分配给该文本字段 然后让委托实现 shouldChangeCharactersInRange 来完成 或者通过将目标添加到文本字段并处理 UIContr
  • 玻璃效果 UIView

    我想知道如何在 UIView 上添加玻璃效果 我想像这样的效果 http pttrns com pickers detail 0dc9d9f6c6a7577613b3453768eee3b3在灰色半透明视图上 您 可以在这里看到 Thank
  • ITMS-90535 无法使用最新的 Google Signin SDK 发布 iOS 应用程序

    我正在使用 xcode 7 GM 种子并通过 cocoapods 安装了最新的 Google Signin SDKpod Google SignIn 当我尝试将我的应用程序发布到苹果应用程序商店时 我收到附加错误 Help 以下是 Goog
  • UIView 子类不会自动调整大小

    我一直在寻找有关调整大小的背景信息 但找不到太多 我知道我需要设置autoresizesSubviews在超级视图和autoresizingMask在子视图上 我已经这样做了 并且我的 UIImageViews 正确调整了大小 但我的自定义
  • 适用于 Objective-C / iPhone 的良好 HTTP 库? [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 UPDATE 这个问题显然已经过时了 参见日期 我建议只使用现代 iOS7 功能 例如 NSURLSession 我想 这个问题是为了历史
  • Objective Flickr 照片上传错误

    我正在使用 ObjectiveFlickr 库将照片从我的 iPhone 应用程序上传到 Flickr 我可以授权该应用程序并执行一般请求 但在尝试上传照片时遇到错误 要上传的照片是使用 AVFoundation 捕获的图像 这是相关代码
  • 避免“在此块中强烈捕获自身可能会导致保留周期”消息

    每次我必须在块内使用全局变量或属性时 如下所示 self save if isItSaving NO self saveMyFile 我必须像这样重写 BOOL iis isItSaving id myself self self save
  • 如何使用 Swift 获取 YouTube 频道的所有播放列表?

    我的问题不是关于从一般频道检索视频 我只想获取该频道创建的所有 播放列表 并检索每个播放列表的缩略图 标题和视频数量 这是一个 YouTube 频道示例 正如您所看到的 有很多已创建的播放列表 截至目前 我只能获取某个频道最新上传的视频 在
  • iPhone 快照,包括键盘

    我正在寻找拍摄整个 iPhone 屏幕 包括键盘 的正确方法 我找到了一些截取屏幕的代码 CGRect screenCaptureRect UIScreen mainScreen bounds UIView viewWhereYouWant
  • PrepareForSegue之谜

    我在两个不同的 VC 中有一个prepareForSegue 方法 一个使用一个if声明 而另一个旨在使用switch 除了名称之外 代码几乎相同 这个效果很好 void prepareForSegue UIStoryboardSegue
  • 我可以知道 requireGestureRecognizerToFail 到底会做什么吗?

    谁能告诉我下面的代码行到底会做什么 我已经提到过Apples https developer apple com library ios documentation uikit reference UIGestureRecognizer C
  • Xcode 3.1.4 中内置分析器

    我想知道 Xcode 3 1 4 中内置的分析器是否使得单独使用 LLVM Clang 静态分析器变得多余 请参考这里的原文 使用 LLVM Clang 静态分析器查找内存泄漏 http www fruitstandsoftware com
  • 对于某些纹理尺寸,glFramebufferTexture2D 在 iPhone 上失败

    当我尝试将纹理附加到帧缓冲区时 glCheckFramebufferStatus 报告某些纹理大小的 GL FRAMEBUFFER UNSUPPORTED 我已经在第二代和第四代 iPod Touch 上进行了测试 两个模型之间失败的纹理尺
  • iPhone - 如何在矩形中间绘制文本

    有没有一种方法可以在矩形中间绘制文本 我可以找到各种对齐方式 但我尝试过的任何方法都不能将文本垂直居中在矩形中 有没有一种简单的方法可以做到这一点 或者有什么方法可以将矩形居中然后在其中绘制 我直接绘制到 CGContext 尝试使用 NS
  • 在 Instruments 中查找内存泄漏行

    我是 iOS 中的仪器新手 我正在尝试使用 Xcode 4 5 2 并按照本教程查找仪器中的内存泄漏 http soulwithmobiletechnology blogspot sg 2011 04 how to check memory
  • Xcode 9 中的“addingPercentEncoding”是否损坏?

    在 Swift 3 x 和 Xcode 9 beta 2 中 使用addingPercentEncoding https developer apple com documentation swift string 1690785 addi
  • 使用 Storyboard 时获取 NSManagedObjectContext

    目标是获取当前的 NSManagedObjectContext 以便使用 Core Data 在 iOS 4 3 中 我将 UINavigationController 的委托设置为 AppDelegate 如下所示 在 AppDelega
  • xcode 6.1 (Swift) 中的 SIGABRT 运行时错误

    与最初的代码相比 唯一的更改是在ViewControl swift override func viewDidLoad newMessage hidden true super viewDidLoad Do any additional s
  • 我应该在哪个方法中设置 UITextField 的委托?

    在 viewDidLoad 或 init 方法中设置 UITextField 的委托是一个好习惯吗 我尝试在 init 方法中将委托设置为 self 但它没有调用相应的委托方法 当我将代码移动到 viewDidLoad 中时 它注册为将 s
  • 显示键盘时如何在 TextView 下方添加更多填充

    当我在 ScrollView 中有 TextField 并点击它时 键盘会按预期显示 但似乎 TextField 已向上移动到足以显示输入区域 但我希望移动到足够的位置 以便整体可见 否则它看起来像是被剪裁了的 我找不到改变这种行为的方法

随机推荐

  • 如何使用任务有条件地异步运行代码

    我有一个负责检索资源的类 该类还缓存它们以便快速访问 该类公开了用于检索资源的异步方法 public Task GetResourceAsync string resourceName return Task Factory StartNe
  • 标头部分中的 ransack 搜索表单:未向 search_form_for 提供 Ransack::Search 对象

    首先 我是 RoR 新手 所以答案可能是显而易见的 在这种情况下我深表歉意 我环顾四周 没有发现任何有帮助的东西 我试图在我的应用程序的每个网页的标题上都有一个搜索表单 它将搜索我所有 存储桶 的名称 这是相关代码 在 app views
  • Rails 身份验证令牌和 Ajax

    好吧 根据我在其他网站和堆栈溢出上读到的内容 Rails 会抛出此身份验证令牌错误 因为我的表单未传递令牌 这是一项安全功能 这我明白了 但我确实没有表格 我这里有 ajax 我的 javascript 将 id ed 信息发布到处理函数中
  • 如何在 Diesel 中针对 Postgres 数据库执行带有子查询的删除?

    我在 Postgres 数据库中有以下架构 Table A ID Name Table B ID FOREIGN KEY A ID 我正在尝试在 Diesel 中编写以下查询 DELETE FROM B WHERE B ID in SELE
  • 如何使用 iBatis 将数组写入 Oracle 10g XE 数据库?

    我一直在寻找这个高低的答案 但找不到答案 基本上我有一个对象正在使用 iBatis 写入我的数据库 这适用于字符串 整数等基本类型 但我的对象的属性之一是其他对象的数组 我希望能够保留这一点 然后调用 selectById 语句并检索包括数
  • 当我通过 socket.io 操作会话时,如何避免 node.js 中的竞争条件?

    我在我的 socket io 设置中使用这个授权函数 io set authorization function data accept if data headers cookie return accept Session cookie
  • UItextField 委托不工作

    在我的 iPad 应用程序中 我有两个文本字段 一个显示正常的默认文本字段 另一个应显示选择器作为其输入视图 问题是 一旦我使用txt1显示默认键盘 然后当我触摸第二个文本字段时txt1键盘保持可见 我也写过 txt1 resignFirs
  • 如何获取RSpec当前的上下文名称?

    如果我有这样的 rspec describe Foo do init go here describe Sub Foo do it should Bar do test go here puts lt need Foo Sub Foo sh
  • 从工具栏提交 SAS 代码或宏

    是否可以将 SAS 脚本或宏分配给 Base SAS 中的工具栏按钮 即 您可以 dm 宏或 sas 脚本吗 当然 这是一种方法 转到工具 gt 自定义 选择自定义选项卡 单击 添加工具 最左边的按钮 命令 一词的正上方 创建一个新的空白按
  • ASP.NET - 条件 Web.config

    我是 ASP 新手 想知道它是否有条件 编译 我知道它没有编译 我的意思是 我的应用程序交付给不同的用户 每个都有自己的条件应用程序编译 现在我需要有条件地更改 Web config 有没有办法使用条件编译符号 EOG 如果 Daniel
  • 在 C++ 中传递具有多个条目的结构

    我试图传递一个坐标 它被定义为具有 2 个整数参数的结构 该结构称为 coord 如下所示 UpdateB 0 0 其中输入参数的类型为 coord 即在上面的语句中我试图传递一个坐标0 0 UpdateB是某种功能 我收到错误 有什么想法
  • 在 Rcpp 中按列对数据框排序

    有没有简单的方法可以通过 RCpp 中的两列 或多列或一列 对 DataFrame 进行排序 网上有很多排序算法 或者我可以使用std sort带有 DataFrame 的包装器 但我想知道 RCpp 或 RCppArmadillo 中是否
  • jQuery click() 没有点击?

    我以为 jQuery 的click 可以让我们添加一个处理程序或仅单击一个元素吗 但是 我尝试过 function setTimeout function a first trigger click or click the same 30
  • 分配空列表

    我真的不知道我是如何偶然发现这个的 我也不知道该怎么想 但显然 是 python 中的合法操作 所以也是 but 不允许 虽然似乎没有任何效果 但我想知道 到底是什么 这和Python的多重赋值 序列拆包 有关 a b c 1 2 3 工作
  • 'FBSession:未提供 AppID

    我刚刚使用新的 iOS 版 Facebook 3 0 SDK 更新了我的应用程序 在此之前 我使用的是利用 FBSessionDelegate 和 FBRequestDelegate 的 SDK 在该 SDK 中 我们必须将此代码放置在 a
  • 应用程序不会从命令行完整路径启动,但会在 CD 到目录后启动

    我正在尝试从注册表运行 Net C 应用程序Run键 在HKEY LOCAL MACHINE SOFTWARE Microsoft Windows CurrentVersion Run 其他字符串值存在并启动一切都很好 但由于某种莫名其妙的
  • 我将华氏温度转换为摄氏度的代码有什么问题?

    Programme to covert Farenheight to Celcius F input Enter Value F F 32 9 5 print The temperature is F Degrees Celcius 当我尝
  • 在 Swift 中使用 NSDate 进行 NSSortDescriptor 排序

    我如何使用托管对象的日期属性对 NSFetchRequest 进行排序 这样它就创建了一个按日期顺序排列的数组 到目前为止 这是我的代码 var request NSFetchRequest NSFetchRequest entityNam
  • 尝试返回父记录的子记录的所有列

    我正在寻找一种解决方案 通过该解决方案可以获得父记录的所有子记录 我找到了一个满足我的需求的解决方案 如下所示 https stackoverflow com a 28366310 726802 唯一的问题是上述解决方案是连接 ID 当前结
  • Google Now 类似于 iOS 上的界面

    所以 我非常喜欢 Android 上的 Google Now 卡片界面 最近它甚至登陆了 iOS 有没有任何教程或示例项目可以帮助我为我的 iOS 应用程序创建卡片界面 根据我的研究 我已经能够使用自定义 UICollectionViewF