IOSUI瀑布流相册的实现

瀑布流相册
TestAppDelegate.m文件下的内容
#import "TestAppDelegate.h"

#import "MainViewController.h"





@implementation TestAppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    

    MainViewController *mainVC = [[MainViewController alloc]init];

    UINavigationController *naviVC = [[UINavigationController alloc]initWithRootViewController:mainVC];

    self.window.rootViewController = naviVC;

    [ _window release];

    [mainVC release];

    [naviVC release];

    

    

    return YES;

}

-(void)dealloc

{

    [_window release];

    [super dealloc];

}

MainViewController.h下的内容
#import <UIKit/UIKit.h>



@interface MainViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, retain)UITableView *tableView;

@property (nonatomic, retain)NSMutableArray *array;

@property (nonatomic,retain)UITableView *tableViewS;

@property (nonatomic, retain)UITableView *tableViewT;

@property (nonatomic, retain)NSMutableArray *arrayS;

@property (nonatomic, retain)NSMutableArray *arrayT;

MainViewConroller.m下的内容

#import "MainViewController.h"
#import "MycellCell.h"
#import "MySecondCell.h"
#import "MyThirdCell.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.arrayT = [NSMutableArray array];
        for (int i = 39; i < 59; i++) {
            UIImage *imageB = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", i]];
            [self.arrayT addObject:imageB];
        }
        
        self.arrayS = [NSMutableArray array];
        for (int i = 20; i < 38; i++) {
            UIImage *imageA = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", i]];
            [self.arrayS addObject:imageA];
        }
        
        self.array = [NSMutableArray array];
        
        for (int i = 1; i < 19 ; i++) {
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", i]];
            
            [self.array addObject:image];
        }
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
        
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, 106, 416) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self.view addSubview:self.tableView];
    [self.tableView release];
    
    self.tableViewS = [[UITableView alloc]initWithFrame:CGRectMake(106, 64, 106, 416) style:UITableViewStylePlain];
    self.tableViewS.delegate = self;
    self.tableViewS.dataSource = self;
    
    [self.view addSubview:self.tableViewS];
    
    [self.tableViewS release];
    
    self.tableViewT = [[UITableView alloc]initWithFrame:CGRectMake(212, 64, 108, 416) style:UITableViewStylePlain];
    self.tableViewT.delegate = self;
    self.tableViewT.dataSource = self;
    [self.view addSubview:self.tableViewT];
    [self.tableViewT release];
    
    
    
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.tableView) {
        NSString *string = @"reuse";
        MycellCell *cell = [tableView dequeueReusableCellWithIdentifier:string];
        if (nil == cell) {
            cell = [[[MycellCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:string]autorelease];
        }
        UIImage *image = [self.array objectAtIndex:indexPath.row];
        cell.MyImageView.image = image;
        return cell;
    }else if (tableView == self.tableViewS) {
        NSString *stringA = @"reuseA";
        MySecondCell *cellA = [tableView dequeueReusableCellWithIdentifier:stringA];
        if (nil ==cellA) {
            cellA = [[MySecondCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:stringA];
        }
        UIImage *imageA = [self.arrayS objectAtIndex:indexPath.row];
        cellA.Myimage.image = imageA;
        return cellA;
        
    }else {
        NSString *stringB = @"reuseB";
        MyThirdCell *cellB = [tableView dequeueReusableCellWithIdentifier:stringB];
        if (nil == cellB) {
            cellB = [[MyThirdCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:stringB];
        }
        UIImage *imageC = [self.arrayT objectAtIndex:indexPath.row];
        cellB.MyImageViewT.image = imageC;
        return cellB;
    }
    
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIImage *image = [self.array objectAtIndex:indexPath.row];
    CGFloat cellHight = tableView.bounds.size.width * image.size.height / image.size.width;
    UIImage *imageA = [self.arrayS objectAtIndex:indexPath.row];
    CGFloat cellAight = tableView.bounds.size.width * imageA.size.height / imageA.size.width;
    UIImage *imageB = [self.arrayT objectAtIndex:indexPath.row];
    CGFloat cellBight = tableView.bounds.size.width * imageB.size.height / imageB.size.width;
    return cellBight;
    return cellAight;
    return cellHight;
}
//让三个tableView的indexpath值等于scrollerView
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.tableView.contentOffset = scrollView.contentOffset;
    self.tableViewS.contentOffset = scrollView.contentOffset;
    self.tableViewT.contentOffset = scrollView.contentOffset;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

MyCellCell.h下的文件

#import <UIKit/UIKit.h>

@interface MycellCell : UITableViewCell

@property (nonatomic, retain)UIImageView *MyImageView;

@end

MyCellCell.m下的文件
#import "MycellCell.h"



@implementation MycellCell



- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self) {

        // Initialization code

        _MyImageView = [[UIImageView alloc]init];

        [self.contentView addSubview:_MyImageView];

        [_MyImageView release];

    }

    return self;

}

- (void)layoutSubviews

{

    [super layoutSubviews];

    self.MyImageView.frame = self.contentView.bounds;

}

- (void)awakeFromNib

{

    // Initialization code

}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated

{

    [super setSelected:selected animated:animated];



    // Configure the view for the selected state

}





@end

MSecondCell.h下的文件
#import <UIKit/UIKit.h>



@interface MySecondCell : UITableViewCell

@property (nonatomic, retain)UIImageView *Myimage;



@end

MSecondCell.m下的文件

#import "MySecondCell.h"

@implementation MySecondCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        _Myimage = [[UIImageView alloc]init];
        
        [self.contentView addSubview:_Myimage];
        [_Myimage release];
        
        
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    self.Myimage.frame = self.contentView.bounds;
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

MyThirdCell.h下的文件

#import <UIKit/UIKit.h>



@interface MyThirdCell : UITableViewCell

@property (nonatomic, retain)UIImageView *MyImageViewT;



@end



MyThirdCell.m下的文件

#import "MyThirdCell.h"

@implementation MyThirdCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        _MyImageViewT = [[UIImageView alloc]init];
        [self.contentView addSubview:_MyImageViewT];
        [_MyImageViewT release];
        
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    self.MyImageViewT.frame = self.contentView.bounds;
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SwiftUI瀑布是一种在iOS应用程序中实现多列不规则布局的技术。它可以让开发者创建出独特而有吸引力的界面,以展示图片、卡片或其他内容。瀑布布局的特点是每个项目的大小和位置都是根据内容自动调整的,形成一个自适应的网格。瀑布通常用于展示图片墙、商品列表和社交媒体的动态内容等场景。 在SwiftUI中实现瀑布布局可以通过使用`LazyVGrid`或`LazyHGrid`结合`GridItem`实现。`GridItem`定义了每个项目的大小和位置,可以设置不同的列数和行数,以及项目之间的间距。通过适当调整`GridItem`的参数,可以实现不同样式的瀑布。 为了实现更复杂的瀑布效果,开发者可以结合自定义动画和过渡效果。通过使用SwiftUI的动画和过渡功能,可以为瀑布中的项目添加平滑的出现和消失效果,增强用户体验。 引用提供了一些关于SwiftUI中实现瀑布的小功能模块的示例代码,可以作为参考。引用提供了相关的技术和运行环境信息。另外,引用提供了一个开源项目的链接,该项目实现了一个滚动横幅效果,可能对实现瀑布布局有所帮助。 总之,SwiftUI瀑布是一种灵活、自适应的布局技术,可以让开发者以创造性的方式展示内容,并通过自定义动画和过渡效果增强用户体验。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [【SwiftUI模块】0003、SwiftUI搭建瀑布-交错网格](https://blog.csdn.net/qq_42816425/article/details/126325803)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Swift 自定义布局实现瀑布视图](https://blog.csdn.net/shenjie12345678/article/details/114574210)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值