ios – 静态子视图背景图像效果

ios – 静态子视图背景图像效果,第1张

概述在最新的iOS版Expedia应用程序中,它们有一个非常有趣的效果,我试图包围我的头脑.有两列无限滚动的子视图我知道可以通过2个滚动视图完成.有趣的是,整体滚动视图似乎具有保持静态的亚麻背景,并且可以在每个子视图单元之间的间隙中看到.真正酷的部分是子视图具有不同的背景,并保持不变.在下面的屏幕截图中,它是城市天际线图像.当子视图滚动时,只能在子视图单元格后面看到城市图像.它似乎是某种掩蔽技巧,但我 在最新的iOS版Expedia应用程序中,它们有一个非常有趣的效果,我试图包围我的头脑.有两列无限滚动的子视图我知道可以通过2个滚动视图完成.有趣的是,整体滚动视图似乎具有保持静态的亚麻背景,并且可以在每个子视图单元之间的间隙中看到.真正酷的部分是子视图具有不同的背景,并保持不变.在下面的屏幕截图中,它是城市天际线图像.当子视图滚动时,只能在子视图单元格后面看到城市图像.它似乎是某种掩蔽技巧,但我无法弄清楚效果是如何完成的.我怎样才能达到相同的效果?

从本质上讲,如何在子视图后面显示静态背景,作为小窗口而不显示亚麻布.亚麻布只应在细胞周围展示.

您可以下载应用程序,点击飞行模式并亲自尝试.

这是一个截图:

这是另一个显示单元格滚动但城市保持不变:

解决方法 我想找到一个优雅的解决方案,现在我会通过跟踪可见的子视图偏移并配置它们的外观来实现.

请在sample project查看结果.

为了将来的参考,我将附上以下代码:

VIEwController.m

////  OSVIEwController.m//  ScrollMasks////  Created by #%$^Q& on 11/30/12.//  copyright (c) 2012 Demo. All rights reserved.//#import "OSVIEwController.h"@interface OSVIEwController ()// subvIEws@property (strong) IBOutlet UIScrollVIEw * scrollVIEw;// all the subvIEws@property (strong) NSArray * maskedSubvIEws;// subvIEws visible at scrollvIEw,we'll update only them@property (strong) NSArray * visibleMaskedSubvIEws;// updates the vIEws from visibleMaskedSubvIEws-(voID) updateVisibleSubvIEws;// updates the visibleMaskedSubvIEws array with the given scrollVIEw offset-(voID) updateVisibleSubvIEwsArrayForOffset:(CGPoint) offset;@end@implementation OSVIEwController-(voID) unused {}#pragma mark - vIEw-(voID) vIEwWillAppear:(BOol)animated {    [self updateVisibleSubvIEws];    [super vIEwWillAppear:animated];}- (voID)vIEwDIDLoad{    [super vIEwDIDLoad];    /*     See -updateVisibleSubvIEws comment for the class comments     */    UIVIEw * newMaskedVIEw = nil;    NSMutableArray * newMaskedSubvIEws = [NSMutableArray array];    const CGSize scrollVIEwSize = self.scrollVIEw.bounds.size;    const int totalSubvIEws = 10;    const float offset = 20.;    const float height = 100.;    UIImage * maskImage = [UIImage imagenamed:@"PeeringFrog.jpg"];    /*     // Uncomment to compare     UIImageVIEw * iv = [[UIImageVIEw alloc] initWithFrame:self.scrollVIEw.bounds];     iv.image = maskImage;     [self.vIEw insertSubvIEw:iv atIndex:0];     */    // add scrollvIEw subvIEws    for (int i = 0; i < totalSubvIEws; i++) {        CGRect newVIEwFrame = CGRectMake(offset,offset*(i+1) + height*i,scrollVIEwSize.wIDth - offset*2,height);        newMaskedVIEw = [UIVIEw new];        newMaskedVIEw.frame = newVIEwFrame;        newMaskedVIEw.clipsToBounds = YES;        newMaskedVIEw.backgroundcolor = [UIcolor redcolor];        newMaskedVIEw.autoresizingMask = UIVIEwautoresizingFlexibleRightmargin | UIVIEwautoresizingFlexibleWIDth;        UIImageVIEw * maskImageVIEw = [UIImageVIEw new];        maskImageVIEw.frame = CGRectMake(0,self.scrollVIEw.bounds.size.wIDth,self.scrollVIEw.bounds.size.height);        maskImageVIEw.image = maskImage;        [newMaskedVIEw addSubvIEw:maskImageVIEw];        [self.scrollVIEw addSubvIEw:newMaskedVIEw];        [newMaskedSubvIEws addobject:newMaskedVIEw];    }    self.scrollVIEw.contentSize = CGSizeMake(scrollVIEwSize.wIDth,(height+offset)*totalSubvIEws + offset*2);    self.maskedSubvIEws = [NSArray arrayWithArray:newMaskedSubvIEws];    [self updateVisibleSubvIEwsArrayForOffset:self.scrollVIEw.contentOffset];}-(voID) updateVisibleSubvIEws {    [self updateVisibleSubvIEwsArrayForOffset:self.scrollVIEw.contentOffset];    for (UIVIEw * vIEw in self.visibleMaskedSubvIEws) {        /*        Todo:         vIEw must be UIVIEw subclass with the imageVIEw initializer and imageVIEw frame update method        */        CGPoint vIEwOffset = [self.vIEw convertPoint:CGPointZero fromVIEw:vIEw];        UIImageVIEw * subvIEw = [[vIEw subvIEws] objectAtIndex:0];        CGRect subvIEwFrame = subvIEw.frame;        subvIEwFrame = CGRectMake(-vIEwOffset.x,-vIEwOffset.y,subvIEwFrame.size.wIDth,subvIEwFrame.size.height);        subvIEw.frame = subvIEwFrame;    }}#pragma mark - scrollvIEw delegate & utilitIEs-(voID) scrollVIEwDIDScroll:(UIScrollVIEw *)scrollVIEw {    [self updateVisibleSubvIEws];}-(voID) updateVisibleSubvIEwsArrayForOffset:(CGPoint) offset {    NSMutableArray * newVisibleMaskedSubvIEws = [NSMutableArray array];    for (UIVIEw * vIEw in self.maskedSubvIEws) {        CGRect intersectionRect = CGRectIntersection(vIEw.frame,self.scrollVIEw.bounds);        if (NO == CGRectIsNull(intersectionRect)) {            [newVisibleMaskedSubvIEws addobject:vIEw];        }    }    self.visibleMaskedSubvIEws = [NSArray arrayWithArray:newVisibleMaskedSubvIEws];}#pragma mark - memory- (voID)dIDReceiveMemoryWarning{    [super dIDReceiveMemoryWarning];    // dispose of any resources that can be recreated.}@end

VIEwController.h

////  OSVIEwController.h//  ScrollMasks////  Created by #%$^Q& on 11/30/12.//  copyright (c) 2012 Demo. All rights reserved.///* PeeringFrog image is taken (and resized) from Apple sample project "PhotoScroller" */#import <UIKit/UIKit.h>@interface OSVIEwController : UIVIEwController <uiscrollviewdelegate>@end
总结

以上是内存溢出为你收集整理的ios – 静态子视图背景图像效果全部内容,希望文章能够帮你解决ios – 静态子视图背景图像效果所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/999349.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-21
下一篇2022-05-21

发表评论

登录后才能评论

评论列表(0条)

    保存