国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS實現側滑欄效果

2019-10-21 18:53:13
字體:
來源:轉載
供稿:網友

效果

 iOS,側滑欄

源碼: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

iOS,側滑欄

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 娄烦县| 乌海市| 高阳县| 余姚市| 同德县| 纳雍县| 阳泉市| 肥东县| 永昌县| 五家渠市| 茌平县| 宜兰市| 荆州市| 涟源市| 安多县| 柘城县| 贵南县| 广德县| 克东县| 精河县| 雷波县| 乌拉特前旗| 阳新县| 巴马| 綦江县| 施甸县| 永宁县| 永德县| 弥渡县| 广南县| 巴东县| 浏阳市| 义乌市| 宣化县| 香格里拉县| 珠海市| 昌吉市| 丰镇市| 兴山县| 昆山市| 瑞安市|