UIKit之App界面Demo

需求

实现简单的APP界面
在这里插入图片描述

功能:

  1. 实现滚动
  2. 实现上层、下层横栏滚动时穿透效果(永远浮在表面,不跟着滚动)。暂用UIView代替,还没学Bar。

分析:

知识点:

  1. 实现鼠标拖动的上下滚动:当把各个带背景图的子控件添加到UIScrollView中时,就能。
  2. 上下导航栏没有参与滚动:它们并不属于UIScrollView的子控件。
    本质是和UIScrollView同层的视图,且有不透明度。
    其中的文字,通过UILabel设置,其它API的原理也一样,都是要通过添加内容到视图上的方式来设置。
  1. 需要掌握USIScrollView三个属性的应用:
    1> 可滚动:设置contentSize。若宽度为屏幕宽度则横向不能滚动,如果高度大于屏幕,则实现滚动。
    2> 初始显示偏移:如下,要让橙色别盖住下面,但是顶层topBar又不是scrollView的子视图。
    要设置偏移量。需要偏移UIView大小加上margintop大小。
    设置contentInsetOffset:CGPointMake(0, -100)。注意偏移量是负数
    3> 但是拖动后,又会恢复原来被覆盖的样子,希望永远不回去,还需要设置内边距,所以是第三个属性:contentInset,参数为(上,左,下,右)。
    请添加图片描述

实现

自定义类:

声明需要的全部组件

关于weak和strong的简单选用:当前类是否拥有它。

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface UIScrollViewHimalayanTest : UIView
// 1. 声明组件:几个按钮:(因为可点击)
/*
 weak或strong选取:当前类拥有它,则声明为strong,否则为weak
 */
@property(nonatomic, strong) UIScrollView* scrollveiw;
@property(nonatomic, strong) UIView* topbar;
@property(nonatomic, strong) UIView* bottombar;

@property(nonatomic, strong) UIButton* l1;
@property(nonatomic, strong) UIButton* l2;
@property(nonatomic, strong) UIButton* l3;
@property(nonatomic, strong) UIButton* r1;
@property(nonatomic, strong) UIButton* r2;
@property(nonatomic, strong) UIButton* r3;
@property(nonatomic, strong) UIButton* bottom1;

@end

实现:

仅仅是scrollView加其它UI的创建和初始化

//
//  UIScrollViewHimalayanTest.m
//  OCUI_Learn
//
//  Created by AAA on 2024/6/3.
//

#import "UIScrollViewHimalayanTest.h"

@implementation UIScrollViewHimalayanTest

-(instancetype) initWithFrame:(CGRect)frame{
   
   
    self = [super initWithFrame:frame];
    if(self){
   
   
        /*
         创建滚动组件、按钮:
            w、h、margin
         contentSize:必须给大小,如果内容很小,必然不能滚动,滚动的本质是UIScrollView的contentSize很大。
                    宽度设置为屏幕宽度即可,这样横向就不能滚动
         
         */
        CGFloat w = (self.frame.size.width - 30) /2;
        CGFloat h = w;
        CGFloat marginleft = 10;
        CGFloat margintop 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值