时间:2021-05-20
效果
源码:https://github.com/YouXianMing/iOS-Project-Examples 中的 SideViewController
//// ViewController.m// SideViewController//// Created by YouXianMing on 16/6/6.// Copyright © 2016年 YouXianMing. All rights reserved.//#import "ViewController.h"#import "LeftViewController.h"#import "MainViewController.h"#import "UIView+SetRect.h"@interface ViewController () { CGFloat _screenWidth;}@property (nonatomic, strong) UIPanGestureRecognizer *panGesture;@property (nonatomic) CGPoint panBeginPoint;@property (nonatomic, strong) LeftViewController *leftViewController;@property (nonatomic, strong) UIView *leftView;@property (nonatomic, strong) MainViewController *mainViewController;@property (nonatomic, strong) UIView *mainView;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Init some value. _screenWidth = Width; // Add backgroundView. UIImageView *backgroundView = [[UIImageView alloc] initWithFrame:self.view.bounds]; backgroundView.image = [UIImage imageNamed:@"back"]; [self.view addSubview:backgroundView]; // LeftViewController self.leftViewController = [[LeftViewController alloc] init]; self.leftView = self.leftViewController.view; [self.view addSubview:self.leftView]; // MainViewController self.mainViewController = [[MainViewController alloc] init]; self.mainView = self.mainViewController.view; [self.view addSubview:self.mainView]; // Pan gesture. self.panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureEvent:)]; [self.mainView addGestureRecognizer:self.panGesture];}- (void)panGestureEvent:(UIPanGestureRecognizer *)gesture { CGPoint translation = [gesture translationInView:gesture.view]; CGPoint velocity = [gesture velocityInView:gesture.view]; CGFloat gap = _screenWidth / 3.f * 2; CGFloat sensitivePosition = _screenWidth / 2.f; if (velocity.x < 0 && _mainView.x <= 0) { // 过滤掉向左侧滑过头的情形 _mainView.x = 0.f; } else { if (gesture.state == UIGestureRecognizerStateBegan) { // 开始 _panBeginPoint = translation; if (_mainView.x >= sensitivePosition) { _panBeginPoint.x -= gap; } } else if (gesture.state == UIGestureRecognizerStateChanged) { // 值变化 _mainView.x = translation.x - _panBeginPoint.x; if (_mainView.x <= 0) { // 过滤掉向左侧滑过头的情形 _mainView.x = 0.f; } } else if (gesture.state == UIGestureRecognizerStateEnded) { // 结束 [UIView animateWithDuration:0.20f animations:^{ _mainView.x >= sensitivePosition ? (_mainView.x = gap) : (_mainView.x = 0); }]; } }}@end以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
最近项目中用到下拉刷新与侧滑删除需要同时实现的情形,所以对LRecyclerView进行了一些了解,在测试侧滑功能时,发现iOS阻塞效果不完整,即当条目处于侧滑
本文介绍如何使用DrawerLayout和NavigationView实现侧滑菜单栏的效果。效果如下:Layout布局NavigationView需要设置app
本课程将带领大家通过自定义控件实现QQ5.0侧滑菜单,课程将循序渐进,首先实现最普通的侧滑菜单,然后引入属性动画与拖动菜单效果相结合,最终实现QQ5.0侧滑菜单
先解释一下这个标题,说的是实现App侧滑返回功能只需要一行代码就能搞定,怎么做到的我待会会说。侧滑所指的就是侧滑返回,后面的介绍过程我将用侧滑表面其意。请看侧滑
闲来无事,写个玩安卓的首页,实现多布局、banner的效果。其中涉及知识点侧滑,pageview切换页面,页面跳转传值及回调数据(在侧滑里)。这些都是基于自己学