日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

仿网易抽屉效果

發布時間:2025/7/14 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 仿网易抽屉效果 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*** 源代碼的鏈接* 鏈接: http://pan.baidu.com/s/1c2hqDzy 密碼: jscx*/#import <UIKit/UIKit.h>@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window;@end #import "AppDelegate.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// Override point for customization after application launch.return YES; }@end #import <UIKit/UIKit.h>@interface ViewController : UIViewController@end #import "ViewController.h" #import "LFCustomButton.h" #import "LFLeftView.h" #import "LFItems.h" #import "LFSmileViewController.h" #import "LFCheerViewController.h" #import "LFHappyViewController.h"const float leftViewTopGap = 120; const float viewAnimateDuration = 0.3; @interface ViewController ()<LFLeftViewDelegate>@property (nonatomic , strong) UIImageView *bgView;//背景圖片 @property (nonatomic , strong) LFLeftView *leftView;//左邊的菜單欄 @property (nonatomic , strong) UIButton *coverBtn;//防止內容被操作的按鈕 @property (nonatomic , strong) UINavigationController *currentVC;//當前控制器@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// controllers = [NSMutableArray array];// 設置背景圖片self.bgView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];self.bgView.backgroundColor = [UIColor blackColor];self.bgView.opaque = 0.3;// 設置可操作(如果在此不設置可操作,它的子視圖是不可以操作的)self.bgView.userInteractionEnabled = YES;[self.view addSubview:self.bgView];LFItems *item = [[LFItems alloc] init];//圖片名item.images = @[@"De",@"Dx",@"monkey"];//標題的名稱item.titles = @[@"開心",@"快樂",@"幸福"];CGPoint point= CGPointMake(0, leftViewTopGap);self.leftView = [[LFLeftView alloc] initWithItem:item originPoint:point];self.leftView.delegate = self;[self.bgView addSubview:self.leftView];LFSmileViewController *smileVC = [[LFSmileViewController alloc] init];[self initVC:smileVC title:@"開心"];LFCheerViewController *cheerVC = [[LFCheerViewController alloc] init];[self initVC:cheerVC title:@"快樂"];LFHappyViewController *happyVC = [[LFHappyViewController alloc] init];[self initVC:happyVC title:@"幸福"];// 默認第一個控制器為當前控制器self.currentVC = self.childViewControllers[0];[self.bgView addSubview:self.currentVC.view]; }/*** 初始化導航控制器** @param vc 控制器* @param title 導航欄的標題*/ - (void)initVC:(UIViewController *)vc title:(NSString *)title{UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:vc];UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"左菜單欄" style:UIBarButtonItemStylePlain target:self action:@selector(showLeftMenuBar)];vc.title = title;vc.navigationItem.leftBarButtonItem = leftItem;[self addChildViewController:navi];[navi.view removeFromSuperview]; }/*** 導航欄左邊按鈕的監聽事件*/ - (void)showLeftMenuBar{NSLog(@"顯示左菜單欄");[self animation]; }/*** 縮小平移動畫*/ - (void)animation{[UIView animateWithDuration:viewAnimateDuration animations:^{//計算縮放的比例float widthScale = 1 - self.leftView.frame.size.width/(UISCREEN_WIDTH*1.0);float heightScale = 1 - (leftViewTopGap * 2)/(UISCREEN_HEIGHT *1.0);//縮放CGAffineTransform scaleTransForm = CGAffineTransformMakeScale(widthScale, heightScale);//計算平移的距離CGFloat distanceX = UISCREEN_WIDTH * (1-widthScale)*0.5;//平移(因為moveTransForm是基于scaleTransForm執行動畫,所以要除以原來的比例(widthScale))CGAffineTransform moveTransForm = CGAffineTransformTranslate(scaleTransForm, distanceX/widthScale, 0);self.currentVC.view.transform = moveTransForm;} completion:^(BOOL finished) {self.coverBtn = [UIButton buttonWithType:UIButtonTypeCustom];self.coverBtn.frame = self.currentVC.view.bounds;self.coverBtn.backgroundColor = [UIColor clearColor];[self.coverBtn addTarget:self action:@selector(coverbtnAction:) forControlEvents:UIControlEventTouchUpInside];[self.currentVC.view addSubview:self.coverBtn];}];}/*** coverBtn按鈕的監聽事件*/ - (void)coverbtnAction:(UIButton *)sender{[self recoverAnimation]; }/*** 恢復原來尺寸的動畫*/ - (void)recoverAnimation{[UIView animateWithDuration:viewAnimateDuration animations:^{self.currentVC.view.transform =CGAffineTransformIdentity;} completion:^(BOOL finished) {[self.coverBtn removeFromSuperview];}]; }#pragma mark -- LFLeftViewDelegate -- - (void)exchangeControllerFromIndex:(int)index toIndex:(int)nextIndex{//移除舊控制器 [self.currentVC.view removeFromSuperview];[self recoverAnimation];//顯示新的控制器UINavigationController *willShowVC = self.childViewControllers[nextIndex];self.currentVC = willShowVC;[self.bgView addSubview:willShowVC.view];}@end #import <UIKit/UIKit.h>@interface LFSmileViewController : UIViewController@end #import "LFSmileViewController.h"@interface LFSmileViewController ()@end@implementation LFSmileViewController- (void)viewDidLoad {[super viewDidLoad];self.view.backgroundColor = [UIColor redColor]; }- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];}@end #import <UIKit/UIKit.h>@interface LFCheerViewController : UIViewController@end #import "LFCheerViewController.h"@interface LFCheerViewController ()@end@implementation LFCheerViewController- (void)viewDidLoad {[super viewDidLoad];self.view.backgroundColor = [UIColor orangeColor]; }- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated. }@end #import <UIKit/UIKit.h>@interface LFHappyViewController : UIViewController@end #import "LFHappyViewController.h"@interface LFHappyViewController ()@end@implementation LFHappyViewController- (void)viewDidLoad {[super viewDidLoad];self.view.backgroundColor = [UIColor yellowColor]; }- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated. }@end #import <Foundation/Foundation.h>@interface LFItems : NSObject/*** images存放圖片名*/ @property (nonatomic , strong) NSArray *images;/*** titles 名稱*/ @property (nonatomic, strong) NSArray *titles;@end #import "LFItems.h"@implementation LFItems/*** 初始化時,給images和titles申請內存*/ - (instancetype)init {self = [super init];if (self) {self.images = [[NSArray alloc] init];self.titles = [[NSArray alloc] init];}return self; }@end #import <UIKit/UIKit.h>@interface LFCustomButton : UIButton@end #import "LFCustomButton.h"const float LFCustomButtonScale = 0.5;@implementation LFCustomButton/*** 重寫按鈕title的尺寸*/ - (CGRect)titleRectForContentRect:(CGRect)contentRect {return CGRectMake(contentRect.size.width * LFCustomButtonScale, 0, contentRect.size.width *(1 - LFCustomButtonScale), contentRect.size.height); }/*** 重寫按鈕Image的尺寸*/ - (CGRect)imageRectForContentRect:(CGRect)contentRect {CGRect titleFrame = CGRectMake(0, 0, contentRect.size.width * LFCustomButtonScale, contentRect.size.height);return titleFrame; }@end #import <UIKit/UIKit.h>@class LFItems; @protocol LFLeftViewDelegate;@interface LFLeftView : UIView@property (nonatomic , weak) id<LFLeftViewDelegate> delegate;/*** 初始化的方法** @param item 數據(title和image)* @param point 在父視圖的初始位置** @return 返回LFLeftView的對象*/ - (LFLeftView *)initWithItem:(LFItems *)item originPoint:(CGPoint)point;@end@protocol LFLeftViewDelegate <NSObject>- (void)exchangeControllerFromIndex:(int)index toIndex:(int)nextIndex;@end #import "LFLeftView.h" #import "LFItems.h" #import "LFCustomButton.h" #import "UIImage+CreatImageWithColor.h" #define LFCustomButtonWidth UISCREEN_WIDTH/2.0 #define LFCustomButtonHeight 60@interface LFLeftView()@property (nonatomic, strong) LFItems *item;@property (nonatomic, strong) NSMutableArray *buttons;@property (nonatomic, strong) UIButton *currentBtn;//當前選中的按鈕@end@implementation LFLeftView- (LFLeftView *)initWithItem:(LFItems *)item originPoint:(CGPoint)point {self = [super init];if (self) {if (item == nil) {return nil;}self.buttons = [NSMutableArray array];self.userInteractionEnabled = YES;self.item = item;self.frame = CGRectMake(point.x, point.y, LFCustomButtonWidth, LFCustomButtonHeight * self.item.titles.count);[self creatButtons];}return self; }/*** 創建按鈕*/ - (void)creatButtons{//創建button的個數int count = (int)self.item.titles.count;// 通過循環創建按鈕for (int i = 0; i < count; i++) {LFCustomButton *button = [LFCustomButton buttonWithType:UIButtonTypeCustom];//設置選中時的背景圖片[button setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithRed:253/255.0 green:0 blue:0 alpha:0.2]] forState:UIControlStateSelected];//默認第一個按鈕為當前選中按鈕if (i == 0) {self.currentBtn = button;self.currentBtn.selected = YES;}button.backgroundColor = [UIColor grayColor];[button setTitle:self.item.titles[i] forState:0];if (self.item.images[i] != nil) {[button setImage:[UIImage imageNamed:self.item.images[i]] forState:0];}button.tag = i;[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];[self addSubview:button];[self.buttons addObject:button];} }/*** 按鈕的監聽事件*/ - (void)buttonAction:(UIButton *)sender{NSLog(@"從第%ld個按鈕跳到第%ld個按鈕",(long)self.currentBtn.tag,(long)sender.tag);if ([_delegate respondsToSelector:@selector(exchangeControllerFromIndex: toIndex:)]) {[_delegate exchangeControllerFromIndex:(int)self.currentBtn.tag toIndex:(int)sender.tag];}//取消當前按鈕選中狀態self.currentBtn.selected = NO;//設置當前按鈕為選中的按鈕self.currentBtn = sender;// 設置當前按鈕為選中狀態self.currentBtn.selected = YES; }- (void)layoutSubviews{[super layoutSubviews];// 設置所有子視圖的尺寸for (int i = 0; i < self.buttons.count; i++) {UIButton *button = self.buttons[i];button.frame = CGRectMake(0, i*LFCustomButtonHeight, LFCustomButtonWidth, LFCustomButtonHeight);} }@end #import <UIKit/UIKit.h>@interface UIImage (CreatImageWithColor)/*** 通過顏色生成該純顏色的圖片** @param color 生成圖片的顏色** @return 返回圖片*/ + (UIImage *)imageWithColor:(UIColor *)color;/*** 通過顏色生成該純顏色的圖片** @param color 生成圖片的顏色* @param width 生成圖片的寬* @param height 生成圖片的高** @return 返回圖片*/ + (UIImage *)imageWithColor:(UIColor *)color imageWidth:(CGFloat)width imageWithHeight:(CGFloat)height;@end #import "UIImage+CreatImageWithColor.h"@implementation UIImage (CreatImageWithColor)+ (UIImage *)imageWithColor:(UIColor *)color{return [UIImage imageWithColor:color imageWidth:100 imageWithHeight:100]; }+ (UIImage *)imageWithColor:(UIColor *)color imageWidth:(CGFloat)width imageWithHeight:(CGFloat)height{//開啟基于位圖的圖形上下文UIGraphicsBeginImageContextWithOptions(CGSizeMake(width,height), NO, 0.0);// 設置畫筆的顏色[color set];// 畫矩形,并填充UIRectFill(CGRectMake(0, 0, width, height));//獲取圖片UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();//關閉上下文 UIGraphicsEndImageContext();return resultImage; }@end #ifndef PrefixHeader_pch #define PrefixHeader_pch// Include any system framework and library headers here that should be included in all compilation units. // You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.#define UISCREEN_WIDTH [UIScreen mainScreen].bounds.size.width #define UISCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height#endif /* PrefixHeader_pch */

?

轉載于:https://www.cnblogs.com/lantu1989/p/5462623.html

總結

以上是生活随笔為你收集整理的仿网易抽屉效果的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 肉大榛一进一出免费视频 | 情侣黄网站免费看 | 国产视频在线一区 | 一级黄网站 | 泰剧19禁啪啪无遮挡 | 干干干日日日 | 福利电影一区二区 | 91理论片午午伦夜理片久久 | 婷婷亚洲五月 | 韩国av毛片 | 国产精品人人爽人人爽 | 亚洲精品二 | 精品国产99 | 日本zzjj | 欧美午夜精品久久久久久孕妇 | 男人的天堂网av | 人人草人人干 | 6080成人| 人妻妺妺窝人体色www聚色窝 | 粉嫩aⅴ一区二区三区 | 一区二区成人在线 | 日日摸日日添日日碰9学生露脸 | 最新日韩中文字幕 | 成人春色影视 | 羞羞的视频网站 | 久久久www成人免费精品 | 综合色婷婷一区二区亚洲欧美国产 | 国产女人和拘做受视频免费 | 亚洲情欲网| 欧美日韩激情视频 | 色综合久久五月 | 杏导航aⅴ福利网站 | 西方av在线 | 成年人在线视频网站 | 在线成人av网站 | 久操伊人网 | 毛片黄色一级 | 日韩一级黄色片 | 欧美极品在线播放 | 精品色 | 国产精品大屁股白浆一区 | 无毒黄色网址 | 性色一区 | 三级视频在线 | av毛片网 | 大又大粗又爽又黄少妇毛片 | 亚洲伦理在线视频 | 国产精选久久 | 亚洲综合国产 | 女人私密又肥又大 | 91在线免费观看网站 | 天天拍夜夜拍 | 男生女生操操操 | 69日影院| 四虎一国产精品一区二区影院 | 精品福利在线 | 男人天堂影院 | 九九热最新 | 欧美第十页| 久久精品日 | 国产在线免费 | 久久视频在线看 | 午夜精品网站 | 亚洲天堂成人av | 四虎成人精品永久免费av | 成人在线观看免费视频 | 天天想你在线观看完整版电影免费 | 夜夜夜爽 | 亚洲精品综合在线观看 | 亚洲成人中文 | 毛片一区二区 | 国产一区二区三区毛片 | 99久久久久 | 亚洲欧美另类激情 | 成人精品一区二区三区四区 | 九九视频国产 | 亚洲午夜av久久乱码 | 男女在楼梯上高潮做啪啪 | 毛片无遮挡 | 国产激情在线视频 | 欧洲一区二区在线 | 琪琪电影午夜理论片八戒八戒 | 婷婷六月天在线 | 天天曰天天操 | exo妈妈mv在线播放高清免费 | 婷婷毛片 | 久久久久久国产精品 | 国产中文在线观看 | 国产一级在线免费观看 | 中文字幕码精品视频网站 | 99久久国产视频 | 手机在线毛片 | 国产午夜精品视频 | 久久精品波多野结衣 | 亚洲高清在线 | av大全在线观看 | 波多野结衣黄色片 | www狠狠爱 | 色屁屁在线 |