
从本质上讲,如何在子视图后面显示静态背景,作为小窗口而不显示亚麻布.亚麻布只应在细胞周围展示.
您可以下载应用程序,点击飞行模式并亲自尝试.
这是一个截图:
这是另一个显示单元格滚动但城市保持不变:
解决方法 我想找到一个优雅的解决方案,现在我会通过跟踪可见的子视图偏移并配置它们的外观来实现.请在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 – 静态子视图背景图像效果所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)