抽屉效果实现

iOS拖拽交互实现
#import "ViewController.h"
#define maxY 60
@interface ViewController ()
@property (nonatomic, weak) UIView *mainView;
@property (nonatomic, weak) UIView *leftView;
@property (nonatomic, weak) UIView *rightView;
@property (nonatomic, assign) BOOL isDraging;
@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // 添加所有子控件
    [self addAllChildView];
     
    // 监听主视图的frame的变化
    [self.mainView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];
}
// 属性变化,会调用此方法
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
     
    if (self.mainView.frame.origin.x < 0) {
        self.rightView.hidden = NO;
        self.leftView.hidden = YES;
    }else if(self.mainView.frame.origin.x > 0){
        self.rightView.hidden = YES;
        self.leftView.hidden = NO;
    }
}
- (void)addAllChildView {
     
    // leftView
    UIView *leftView = [[UIView alloc] initWithFrame:self.view.bounds];
    leftView.backgroundColor = [UIColor greenColor];
    leftView.alpha = 0.3;
    [self.view addSubview:leftView];
    self.leftView = leftView;
     
    // rightView
    UIView *rightView = [[UIView alloc] initWithFrame:self.view.bounds];
    rightView.backgroundColor = [UIColor redColor];
    rightView.alpha = 0.3;
    [self.view addSubview:rightView];
     
    // mainView
    UIView *mainView = [[UIView alloc] initWithFrame:self.view.bounds];
    mainView.backgroundColor = [UIColor blueColor];
    mainView.alpha = 0.3;
    [self.view addSubview:mainView];
    self.mainView = mainView;
}
// 添加拖拽方法
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
     
    // 获取手指
    UITouch *touch = [touches anyObject];
     
    CGPoint curP = [touch locationInView:self.view];
     
    CGPoint preP = [touch previousLocationInView:self.view];
     
    // 获取手指每移动一下, X轴的偏移量
    CGFloat offsetX = curP.x - preP.x;
     
    // 设置当前视图的frame
    self.mainView.frame = [self frameWithOffsetX:offsetX];
     
    // 记录下当前正在拖拽
    self.isDraging = YES;
}
// 根据X的偏移量计算出当前视图的frame
- (CGRect)frameWithOffsetX:(CGFloat)offsetX {
    CGFloat screenW = [UIScreen mainScreen].bounds.size.width;
    CGFloat screenH = [UIScreen mainScreen].bounds.size.height;
     
    // 获取手指每偏移一点, Y值需要偏移多少
    CGFloat offsetY = offsetX * maxY / screenW;
     
    // 获取缩放比例
    CGFloat scale = (screenH - 2 * offsetY) / screenH;
     
    if (self.mainView.frame.origin.x < 0) {
        scale = (screenH + 2 * offsetY) / screenH;
    }
     
    // 计算当前视图的frame
    CGRect frame = self.mainView.frame;
    frame.origin.x += offsetX;
    frame.size.height = frame.size.height * scale;
    frame.size.width = frame.size.width * scale;
    frame.origin.y = (screenH - frame.size.height) * 0.5;
     
    return frame;
}
#define targetRX 300
#define targetLX -250
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
     
    if (self.isDraging == NO && self.mainView.frame.origin.x != 0) {
        [UIView animateWithDuration:0.25 animations:^{
            self.mainView.frame = self.view.bounds;
        }];
        return;
    }
     
    // 定位功能
    CGFloat screenW = [UIScreen mainScreen].bounds.size.width;
    // 获取当前主视图的frame
    CGRect frame = self.mainView.frame;
     
    CGFloat target = 0;
    if (frame.origin.x > screenW * 0.5) { //
        target = targetRX;
    }else if(CGRectGetMaxX(self.mainView.frame) < screenW * 0.5){
        // 定位到左边
        target = targetLX;
    }
              
    if(target == 0) {
        [UIView animateWithDuration:0.25 animations:^{
            self.mainView.frame = self.view.bounds;
        }];
    }else {
        [UIView animateWithDuration:0.25 animations:^{
            // 获取X轴的偏移量
            CGFloat offsetX = target - frame.origin.x;
            self.mainView.frame = [self frameWithOffsetX:offsetX];
        }];
    }
     
    // 没有拖拽
    self.isDraging = NO;
}
在自媒体领域,内容生产效率与作品专业水准日益成为从业者的核心关切。近期推出的Coze工作流集成方案,为内容生产者构建了一套系统化、模块化的创作支持体系。该方案通过预先设计的流程模块,贯穿选题构思、素材整理、文本撰写、视觉编排及渠道分发的完整周期,显著增强了自媒体工作的规范性与产出速率。 经过多轮实践验证,这些标准化流程不仅精简了操作步骤,减少了机械性任务的比重,还借助统一的操作框架有效控制了人为失误。由此,创作者得以将主要资源集中于内容创新与深度拓展,而非消耗于日常执行事务。具体而言,在选题环节,系统依据实时舆情数据与受众偏好模型生成热点建议,辅助快速定位创作方向;在编辑阶段,则提供多套经过验证的版式方案与视觉组件,保障内容呈现兼具美学价值与阅读流畅性。 分发推广模块同样经过周密设计,整合了跨平台传播策略与效果监测工具,涵盖社交网络运营、搜索排序优化、定向推送等多重手段,旨在帮助内容突破单一渠道局限,实现更广泛的受众触达。 该集成方案在提供成熟模板的同时,保留了充分的定制空间,允许用户根据自身创作特性与阶段目标调整流程细节。这种“框架统一、细节可变”的设计哲学,兼顾了行业通用标准与个体工作习惯,提升了工具在不同应用场景中的适应性。 从行业视角观察,此方案的问世恰逢其时,回应了自媒体专业化进程中对于流程优化工具的迫切需求。其价值不仅体现在即时的效率提升,更在于构建了一个可持续迭代的创作支持生态。通过持续吸纳用户反馈与行业趋势,系统将不断演进,助力从业者保持与行业发展同步,实现创作质量与运营效能的双重进阶。 总体而言,这一工作流集成方案的引入,标志着自媒体创作方法向系统化、精细化方向的重要转变。它在提升作业效率的同时,通过结构化的工作方法强化了内容产出的专业度与可持续性,为从业者的职业化发展提供了坚实的方法论基础。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值