iOS(四)动漫App:四

本文分享了iOS应用UI设计经验,重点介绍了如何使用UITableView及其自定义cell来展示动画和漫画列表,包括布局调整、代理方法及跳转实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本次主要讲中间的三个按钮以及tableViewCell

先说说中间那三个按钮吧;其实这是我留下的一个坑,因为我就用了个xib,然后再xib里定义它的位置和大小,以及背景图片,再.m写了代理被点击后触发的函数,当然触发还是空白的,但我留着这三个按钮,主要是因为当时为了让它适配iPhone4和iPhone5的屏幕,三个按钮里屏幕边框的距离,三个按钮之间的间距,上下间距,着实让我头疼了很久,结果再xib里设置了一下Autoresizing(感觉没这个简单),勉强的解决了


代码也是相对的简单

HomeheaderView.h

#import <UIKit/UIKit.h>

@protocol HomeheaderViewDelegate;

@interface HomeheaderView : UIView
{
    __weak id<HomeheaderViewDelegate> _delegate;
}

@property(weak,nonatomic)id<HomeheaderViewDelegate> delegate;
@property(weak,nonatomic)IBOutlet UIButton *recommendButton;
@property(weak,nonatomic)IBOutlet UIButton *comicButton;
@property(weak,nonatomic)IBOutlet UIButton *animationButton;

@end

@protocol HomeheaderViewDelegate <NSObject>

@optional
-(void)didClickButton:(UIButton *)sender;

@end

HomeheaderView.m

#import "HomeheaderView.h"

@implementation HomeheaderView

-(void)awakeFromNib{
    [_recommendButton addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [_comicButton addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [_animationButton addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)click:(UIButton *)sender{
    if (!_delegate) {
        NSLog(@"delegate is nil");
    }else{ NSLog(@"delegate is exist");}
    if([_delegate respondsToSelector:@selector(didClickButton:)])
    {
        [_delegate didClickButton:sender];
    }
}

@end

HomeheaderView.xib


接着讲人气动画与人气漫画


这个明显是用了tableView和tableViewCell

HomepageViewController.xib拖了一个tableview控件(其实只要用代码定义就行了。。。当时太年轻)

#import "BaseViewController.h"
#define kSectionX kScreenWidth/2 - 75
#define kSectionY 10
#define kSectionWidth 150
#define kSectionHeight 20
#define kScreenWidth        [UIScreen mainScreen].bounds.size.width
#define kScreenHeight       [UIScreen mainScreen].bounds.size.height
#define kTabBarHeight       self.tabBar.frame.size.height
#define kZSGBgColor         [UIColor colorWithRed:254.f/255.f green:87.f/255.f blue:178.f/255.f alpha:1]
@class HomeheadScroll;
@interface HomepageViewController : BaseViewController
@property(strong,nonatomic)IBOutlet HomeheadScroll *homeScrollView;
@property(weak,nonatomic)IBOutlet UITableView *homePageTableView;<span style="white-space:pre">	</span>//tableView

@property(nonatomic,copy)NSMutableArray *block_name;
@property(nonatomic,copy)NSMutableArray *block_picture;
@property(nonatomic,copy)NSMutableArray *block_intro;

@end


tableView的代理

每一个代理前都已经写明了这个函数的作用

#pragma mark- tableView的函数

//返回tableView的分组数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

//为一个section添加一个header view
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 1) {
        
        return [self viewAndImageName:@"new_comic"];
    }else if (section == 2) {
        
        return [self viewAndImageName:@"new_animation"];
    }
    return nil;
}

- (UIView *)viewAndImageName:(NSString *)imageName {
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
    imageView.frame = CGRectMake(kSectionX, kSectionY-20, kSectionWidth, kSectionHeight);
    [view addSubview:imageView];
    return view;
}

//返回每一组行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (!self.data) {
        return 0;
    }
    if(section == 1) {
        NSArray *nsarray_data=[self.data comic];
        return [nsarray_data count];
    }
    else if (section == 2) {
        NSArray *nsarray_data=[self.data animation];
        NSLog(@"hhhh%lu",(unsigned long)[nsarray_data count]);
        return [nsarray_data count];
    }

    return 0;

}

//通过indexPath 来设定每一行行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==1) {
        return 100;
    }
    else if(indexPath.section==2){
        return 100;}
    return 0;
}

//设置TableView中每一行显示的内容和格式的
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
        NSDictionary *cell_tableview_data;
        NSDictionary *cell_tableview_data_ani;
    
        if (indexPath.section==1) {


        HomepageViewcell *cell=[HomepageViewcell cellWithTableView:tableView];
            cell.delegate=self;
        NSArray *cell_data=[self.data comic];
        cell_tableview_data=[cell_data objectAtIndex:indexPath.row];
            //NSLog(@"%d",indexPath.row);
      
        cell.block_name=[cell_tableview_data video_name];
        cell.block_picture=[cell_tableview_data video_image];
        NSLog(@"%@",[cell_tableview_data video_intro]);
        cell.block_intro=[cell_tableview_data video_intro];
        cell.block_id=indexPath.row;
        cell.block_section=indexPath.section;
        return cell;
    } else if (indexPath.section==2)
    {
     HomepageViewcell *cell_ani=[HomepageViewcell cellWithTableView:tableView];
        cell_ani.delegate=self;

        NSArray *cell_data=[self.data animation];
        cell_tableview_data_ani=[cell_data objectAtIndex:indexPath.row];
            //NSLog(@"%d",indexPath.row);
    
        cell_ani.block_name=[cell_tableview_data_ani video_name];
        cell_ani.block_picture=[cell_tableview_data_ani video_image];
        NSLog(@"%@",[cell_tableview_data_ani video_intro]);
        cell_ani.block_intro=[cell_tableview_data_ani video_intro];
        cell_ani.block_id=indexPath.row;
        cell_ani.block_section=indexPath.section;
        return cell_ani;
    }
    return nil;
}


tableViewCell我自己写了一个HomepageViewcell

这是HomepageViewcell.xib


HomepageViewcell.h

我定义cell中block_name(名字);block_image(图片路径),block_intro(作品介绍),block_url(作品路径),

block_section(哪一个section) block_index(section中的第几个),并且声明要重定义一个方法,和一个代理协议

#import <UIKit/UIKit.h>

@protocol HomepageViewcellDelegate;

@interface HomepageViewcell : UITableViewCell
{
    __weak id<HomepageViewcellDelegate> _delegate;
}

@property(weak,nonatomic)id<HomepageViewcellDelegate>delegate;

@property(nonatomic,strong)NSString *block_name;
@property(nonatomic,strong)NSString *block_picture;
@property(nonatomic,strong)NSString *block_intro;
@property(nonatomic,assign)NSInteger block_section;
@property(nonatomic,assign)NSInteger block_index;
+(instancetype)cellWithTableView:(UITableView *)tableView;
@end

@protocol HomepageViewcellDelegate <NSObject>

@optional
-(void)didClickcomic:(HomepageViewcell *)view atindex:(NSInteger)index atsection:(NSInteger)section;

@end


HomapageViewcell.m这里就是实现重定义的方法,以及变量的赋值


#import "HomepageViewcell.h"
#import "AFNetworkTool.h"

@interface HomepageViewcell()
@property(nonatomic,weak)IBOutlet UIButton *icon;
@property(nonatomic,weak)IBOutlet UILabel *name;
@property(nonatomic,weak)IBOutlet UILabel *intro;
@end
@implementation HomepageViewcell

//实现重定义的方法
+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID=@"HomepageViewCell";
    HomepageViewcell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell==nil) {
        cell=[[[NSBundle mainBundle]loadNibNamed:@"HomepageViewcell" owner:nil options:nil]lastObject];
        NSLog(@"xib");
    }
    return cell;
}

-(void)setBlock_name:(NSString *)block_name{
    self.name.text=block_name;
}
-(void)setBlock_picture:(NSString *)block_picture{
  NSString *image_url=block_picture;
  NSLog(@"%@",image_url);
  [AFNetworkTool imageRequestWithUrl:image_url success:^(UIImage *image_s)
   { [self.icon setImage:image_s forState:UIControlStateNormal]; } fail:^{
        NSLog(@"图片加载失败");
    }];
    
    [self.icon addTarget:self action:@selector(icon_button:) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)setBlock_intro:(NSString *)block_intro{
    self.intro.text=block_intro;
}

-(void)icon_button:(UIButton *)sender{
//    NSLog(@"icon_button:%d,%d",self.block_section,self.block_index);
//    if (!_delegate) {
//        NSLog(@"delegate is nil");
//    }
    if ([_delegate respondsToSelector:@selector(didClickcomic:atindex:atsection:)]) {
        NSLog(@"icon_button");
       [_delegate didClickcomic:self atindex:_block_index atsection:_block_section];
    }else{
        NSLog(@"fail");
    }
}
@end

最后讲一下我声明的代理协议

//tableViewCell动画or漫画的跳转
- (void)didClickcomic:(HomepageViewcell *)view atindex:(NSInteger)index atsection:(NSInteger)section
{
    NSDictionary *data;
    NSString *image_url;
    NSArray *comic_data;
    if (section==1) {
     if (comic_data==nil) {
            comic_data=[self.data comic];
        }
    data=[comic_data objectAtIndex:index];
    image_url=[data video_url];
        
    KxMovieViewController *comicVC = [KxMovieViewController movieViewControllerWithContentPath:image_url parameters:nil];
        
    [self.navigationController pushViewController:comicVC animated:YES];
    }
    else if (section==2){
        if (comic_data==nil) {
            comic_data=[self.data animation];
        }
        
        data=[comic_data objectAtIndex:index];
        
        scrollviewcontroller *animationVC=[[scrollviewcontroller alloc]init];
        animationVC.url=[data video_url];
        animationVC.num=[data page_num];
        [self.navigationController pushViewController:animationVC  animated:YES];
    }

}

不难看出来,每次我点击后,会判断是哪一个section是动画or漫画?然后初始化不同控制器,一个播发器控制器,一个图片浏览器控制器,接着把数据传递进去,然后让他们负责,我就不管了,至于视频播放控制器是采用第三方框架FFmpeg,图片播放器是根据我之前自己写的Scrollview图片循环播放改写,把循环给去掉了,并重新添加了一个阉割版的”SDwebimage“框架用来获取图片


下一篇 主要讲分类控制器,其实分类在设计的时候思考过很多方法,是在远程服务器上面分类数据,然后传送过来,还是将所有数据全部传到ios的sqlite数据库里,本地再进行筛选 http://blog.youkuaiyun.com/u012723810/article/details/50493045

内容概要:本文档提供了关于“微型车间生产线的设计与生产数据采集试验研究”的毕业设计复现代码,涵盖从论文结构生成、机械结构设计、PLC控制系统设计、生产数据采集与分析系统、有限元分析、进度管理、文献管理和论文排版系统的完整实现。通过Python代码和API调用,详细展示了各个模块的功能实现和相互协作。例如,利用SolidWorks API设计机械结构,通过PLC控制系统模拟生产流程,使用数据分析工具进行生产数据的采集和异常检测,以及利用进度管理系统规划项目时间表。 适合人群:具有机械工程、自动化控制或计算机编程基础的学生或研究人员,尤其是从事智能制造领域相关工作的人员。 使用场景及目标:①帮助学生或研究人员快速搭建和理解微型车间生产线的设计与实现;②提供完整的代码框架,便于修改和扩展以适应不同的应用场景;③作为教学或科研项目的参考资料,用于学习和研究智能制造技术。 阅读建议:此资源不仅包含详细的代码实现,还涉及多个学科领域的知识,如机械设计、电气控制、数据分析等。因此,在学习过程中,建议读者结合实际操作,逐步理解每个模块的功能和原理,并尝试调整参数以观察不同设置下的系统表现。同时,可以参考提供的文献资料,深入研究相关理论和技术背景。
本次的学生体质健康信息管理网站,按照用户的角色可以分为教师与学生,后台设置管理员角色来对学生的信息进行管理。,设计如下: 1、后台管理系统 后台管理系统主要是为该系统的管理员提供信息管理服务的系统,具体包括的功能模块如下: (1)管理员信息管理 (2)教师信息管理 (3)学生信息管理 (4)健康信息统计(图形化进行健康,亚健康等学生的信息数量统计) 2、教师角色的功能模块设计 教师角色所需要的功能模块主要包括了如下的一些内容: (1)个人资料修改 (2)学生体质健康管理:录入相关数据,包括但不限于身高、体重、肺活量、视力等生理指标以及运动能力、身体成分、骨密度等健康指标,并且设置健康,亚健康状态 (3)学生健康建议:根据体质信息,进行学生健康的建议 (4)健康预警:对健康出问题的学生,进行健康预警 (5)饮食和锻炼情况管理,查看 3、学生角色 学生角色可以通过该信息网站看到个人的基本信息,能够看到教师给与学生的健康建议等,功能模块设计如下: (1)个人资料修改 (2)我的健康建议查看 (3)我的健康预警 (4)饮食和锻炼情况管理,记录平时的饮食和锻炼情况 完整前后端源码,部署后可正常运行! 环境说明 开发语言:Java后端 框架:ssm,mybatis JDK版本:JDK1.8+ 数据库:mysql 5.7+ 数据库工具:Navicat11+ 开发软件:eclipse/idea Maven包:Maven3.3+ 部署容器:tomcat7.5+
网站前台: (1)站内新闻:及时发布康复中心动态、行业资讯等,让用户了解最新消息。 (2)用户注册,登录:支持用户注册新账号并登录系统,开启预约等操作。 (3)科室介绍:详细介绍康复中心各科室,含功能、特色治疗等信息。 (4)医生列表,详情:展示医生信息,如履历、擅长领域,助用户选医生。 (5)老年生活风采:呈现老年人康复生活照片等,展示康复后的精彩状态。 (6)预约入院:用户填写姓名、电话等信息,提交入院预约申请。 网站后台: 管理员 (1)管理员密码修改:管理员可自主修改登录密码,保障账号安全。 (2)用户注册管理,审核:对新用户注册信息审核,确保信息真实合规。 (3)站内新闻管理:发布、编辑、删除站内新闻,把控资讯更新与质量。 (4)科室信息管理:维护科室信息,包括介绍、设备等内容的增删改。 (5)医生信息管理:管理医生资料,可更新履历、擅长方向等信息。 (6)老年生活风采管理:上传、整理、替换老年生活风采相关展示内容。 (7)预约入院管理:处理用户入院预约,安排入院时间和流程。 用户 (1)用户资料修改:用户可修改个人注册资料,保证信息准确性。 (2)我的预约住院结果:查询预约入院审核结果,了解住院安排情况。 完整前后端源码,部署后可正常运行! 环境说明 开发语言:Java后端 框架:ssm,mybatis JDK版本:JDK1.8+ 数据库:mysql 5.7+ 数据库工具:Navicat11+ 开发软件:eclipse/idea Maven包:Maven3.3+ 部署容器:tomcat7.5+
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值