热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

iOS开发之实现一个APP界面框架

在上一篇博客中,给大家介绍了一下我们传统的APP界面框架—标签导航的一些优缺点,在这篇文章中我会来给大家演示,如何用代码去实现这一框架。本

在上一篇博客中,给大家介绍了一下我们传统的 APP 界面框架—标签导航的一些优缺点,在这篇文章中我会来给大家演示,如何用代码去实现这一框架。本次的实现我会分成俩部分来讲,好了闲话少说,接下来进入到开发阶段。

先来一张最终的效果图瞅一眼:

这里写图片描述

接下来,创建一个 Xcode 工程,我取名叫做CoolFrame,该项目我到时候会托管到 GitHub 上去维护,地址我会在下一篇博文中给出。

根据上图的样式,可以把界面分成三部分:导航栏,中间内容,以及底部的TabBar。我们先从简单的中间内容开始编码做起,这里我根据我底部有四个tabbar,所以定义了四个UIViewController,每个UIViewController很简单,主要是为了能够区分我下方点击的是哪一个TabBarItem,每个UIViewController中都用一个固定的英文字母显示在正中央,这里就列举其中一个界面的代码:

#import "FirstViewController.h"@interface FirstViewController ()@end@implementation FirstViewController
@synthesize label = _label;- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.self.title = @"A";[self.view setBackgroundColor:[UIColor whiteColor]];[[self label] setFrame:CGRectMake(roundf(self.view.frame.size.width - 100)/2, roundf(self.view.frame.size.height - 100)/2, 100, 100)];[self.label setTextAlignment:NSTextAlignmentCenter];[self.label setFont:[UIFont fontWithName:@"HiraKakuProN-W3" size:40.0f]];[self.label setText:@"A"];[self.view addSubview:[self label]];
}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}- (UILabel *)label{if(!_label){_label = [[UILabel alloc] init];}return _label;
}@end

中间部分很简单,接下来咱们来说说底部的 tabbar 是怎么实现的,先来看下效果图:

这里写图片描述

我来把效果图构造拆分成四个 UIButton 和一个 UIView ,这样是不是就很容易明白了,UIView 作为一个背景框里面填补了四个按钮,当我们选中其中一个按钮的时候中间就切换到对应的界面,随后按钮的背景色也随之改变。当然,在这里我们要实现的可以一个可以用作商业用途的框架,所以说我们这里的按钮就不可能是 Xcode 给我们提供的按钮,我们得需要自定义一个按钮,这样才能让我们的 UI 更加的美观,好了,这里附上按钮的代码:

//
// CustomTabBarItem.m
// CoolFrame
//
// Created by silicon on 2017/7/25.
// Copyright © 2017年 com.snailgames.coolframe. All rights reserved.
//#import "CustomTabBarItem.h"
#define RGB(r, g, b) [UIColor colorWithRed:(r)/255.f green:(g)/255.f blue:(b)/255.f alpha:1.f]
@implementation CustomTabBarItem- (id)initWithFrame:(CGRect)frame{self = [super initWithFrame:frame];if(self){[self commonInitialization];}return self;
}- (id)init{return [self initWithFrame:CGRectZero];
}- (void)commonInitialization{[self setBackgroundColor:[UIColor clearColor]];_title = @"";_titlePositionAdjustment = UIOffsetZero;_unselectedTitleAttributes = @{NSFontAttributeName: [UIFont systemFontOfSize:10],NSForegroundColorAttributeName: RGB(0, 0, 0)};_selectedTitleAttributes = [_unselectedTitleAttributes copy];_badgeBackgroundColor = [UIColor redColor];_badgeTextColor = [UIColor whiteColor];_badgeTextFont = [UIFont systemFontOfSize:12];_badgePositionAdjustment = UIOffsetZero;
}- (void)drawRect:(CGRect)rect{CGSize frameSize = self.frame.size;CGSize titleSize = CGSizeZero;CGSize imageSize = CGSizeZero;NSDictionary *titleAttribute = nil;UIImage *backgroundimage = nil;UIImage *image = nil;CGFloat imageStartingY = 0.0f;if([self isSelected]){image = [self selectedImage];backgroundimage = [self selectedBackgroundImage];titleAttribute = [self selectedTitleAttributes];if(!titleAttribute){titleAttribute = [self unselectedTitleAttributes];}}else{image = [self unselectedImage];backgroundimage = [self unselectedBackgroundImage];titleAttribute = [self unselectedTitleAttributes];}imageSize = [image size];CGContextRef context = UIGraphicsGetCurrentContext();CGContextSaveGState(context);[backgroundimage drawInRect:self.bounds];if(!_title){[image drawInRect:CGRectMake(roundf(frameSize.width / 2 - imageSize.width / 2) +_imagePositionAdjustment.horizontal,roundf(frameSize.height / 2 - imageSize.height / 2) +_imagePositionAdjustment.vertical,imageSize.width, imageSize.height)];}else{titleSize = [_title boundingRectWithSize:CGSizeMake(frameSize.width, 20)options:NSStringDrawingUsesLineFragmentOriginattributes:@{NSFontAttributeName: titleAttribute[NSFontAttributeName]}context:nil].size;imageStartingY = roundf((frameSize.height - imageSize.height - titleSize.height) / 2);[image drawInRect:CGRectMake(roundf(frameSize.width / 2 - imageSize.width / 2) +_imagePositionAdjustment.horizontal,imageStartingY + _imagePositionAdjustment.vertical,imageSize.width, imageSize.height)];CGContextSetFillColorWithColor(context, [titleAttribute[NSForegroundColorAttributeName] CGColor]);[_title drawInRect:CGRectMake(roundf(frameSize.width / 2 - titleSize.width / 2) +_titlePositionAdjustment.horizontal,imageStartingY + imageSize.height + _titlePositionAdjustment.vertical,titleSize.width, titleSize.height)withAttributes:titleAttribute];}CGContextRestoreGState(context);
}#pragma mark - Image configuration- (UIImage *)finishedSelectedImage{return [self selectedImage];
}- (UIImage *)finishedUnselectedImage{return [self unselectedImage];
}- (void)setFinishedSelectedImage:(UIImage *)selectedImage withFinishedUnselectedImage:(UIImage *)unselectedImage{if(selectedImage && selectedImage != [self selectedImage]){[self setSelectedImage:selectedImage];}if(unselectedImage && unselectedImage != [self unselectedImage]){[self setUnselectedImage:unselectedImage];}
}- (void)setBadgeValue:(NSString *)badgeValue{_badgeValue = badgeValue;[self setNeedsDisplay];
}#pragma mark - Background configuration- (UIImage *)backgroundSelectedImage{return [self backgroundSelectedImage];
}- (UIImage *)backgroundUnselectedImage{return [self backgroundUnselectedImage];
}- (void)setBackgroundSelectedImage:(UIImage *)selectedImage withUnselectedImage:(UIImage *)unselectedImage{if(selectedImage && selectedImage != [self selectedBackgroundImage]){[self setSelectedBackgroundImage:selectedImage];}if(unselectedImage && unselectedImage != [self unselectedBackgroundImage]){[self setUnselectedBackgroundImage:unselectedImage];}
}@end

搞定了按钮,接下来就要把按钮聚集在一起,所以需要写一个按钮容器视图,不管有多少个按钮都可以让他们在这个容器中和谐的铺展开来,并且在这个类中,还要为按钮添加必要的响应事件,容器视图也是作为一个子视图存在,所以我们这边就定义一个 UIView 即可,具体代码如下:

#import
#include "CustomTabBarItem.h"
@protocol CustomTabbarDelegate;@interface CustomTarbar : UIView
@property (nonatomic, strong) id delegate;
@property (nonatomic, strong) NSArray *items;
@property (nonatomic, strong) CustomTabBarItem *selectedItem;
@property (nonatomic, strong) UIView *backgroundView;
@property (nonatomic) CGFloat itemWidth;
@property (nonatomic) CGFloat miniContentHeight;@end@protocol CustomTabbarDelegate - (BOOL)tabBar:(CustomTarbar *)tabBar shouldSelectItemAtIndex:(NSInteger)index;
- (void)tabBar:(CustomTarbar *)tabBar didSelectItemAtIndex:(NSInteger)index;@end

//
// CustomTarbar.m
// CoolFrame
//
// Created by silicon on 2017/7/25.
// Copyright © 2017年 com.snailgames.coolframe. All rights reserved.
//#import "CustomTarbar.h"@implementation CustomTarbar
@synthesize delegate = _delegate;
@synthesize items = _items;
@synthesize selectedItem = _selectedItem;
@synthesize backgroundView = _backgroundView;
@synthesize miniContentHeight = _miniContentHeight;
@synthesize itemWidth = _itemWidth;- (id)initWithFrame:(CGRect)frame{self = [super initWithFrame:frame];if(self){[self commonInitlization];}return self;
}- (id)init{return [self initWithFrame:CGRectZero];
}- (void)commonInitlization{self.backgroundView = [[UIView alloc] init];[self addSubview:self.backgroundView];
}- (void)layoutSubviews{CGSize framesize = self.frame.size;CGFloat height = self.miniContentHeight;[self.backgroundView setFrame:CGRectMake(0, framesize.height - height, framesize.width, framesize.height)];[self setItemWidth:roundf(framesize.width / self.items.count)];int index = 0;for (CustomTabBarItem *item in [self items]) {CGFloat itemHeight = item.itemHeight;if(!itemHeight){itemHeight = framesize.height;}[item setFrame:CGRectMake(self.itemWidth * index, framesize.height - height, self.itemWidth, itemHeight)];[item setNeedsDisplay];index++;}
}#pragma mark - meathod
- (void)setItemWidth:(CGFloat)itemWidth{if(itemWidth > 0){_itemWidth = itemWidth;}
}- (void)setItems:(NSArray *)items{_items = items;for(CustomTabBarItem *item in items){[item addTarget:self action:@selector(tabBarItemWasSelected:) forControlEvents:UIControlEventTouchUpInside];[self addSubview:item];}
}- (CGFloat)miniContentHeight{CGFloat minimumConentHeight = CGRectGetHeight(self.frame);for (CustomTabBarItem *item in [self items]) {CGFloat height = [item itemHeight];if(height && height }#pragma mark -Item selection
- (void)tabBarItemWasSelected:(id)sender{if([[self delegate] respondsToSelector:@selector(tabBar:shouldSelectItemAtIndex:)]){NSInteger index = [self.items indexOfObject:sender];if(![[self delegate] tabBar:self shouldSelectItemAtIndex:index]){return;}}[self setSelectedItem:sender];if([[self delegate] respondsToSelector:@selector(tabBar:didSelectItemAtIndex:)]){NSInteger index = [self.items indexOfObject:self.selectedItem];[[self delegate] tabBar:self didSelectItemAtIndex:index];}
}- (void)setSelectedItem:(CustomTabBarItem *)selectedItem{if(selectedItem == _selectedItem){return;}[_selectedItem setSelected:NO];_selectedItem = selectedItem;[_selectedItem setSelected:YES];
}@end

到这里,我们的开发进度差不多已经完成了 50% ,但是我们的 App 还不能够顺利的运行起来,因为我们还缺一个视图控制类,我们前面开发完成了:主要内容界面,按钮以及存放按钮的容器,但这些类别都是单独存在的,我们需要一个组织者能够把他们串起来,这就要求我们还要再开发一个控制器类,那该如何下手呢!其实很简单,因为我们的按钮有自己的点击事件,只要能够告诉我们的控制器是哪个按钮点击了,那我们不就可以去切换那妞,控制去显示主界面了嘛!这里就要用到代理 Delegate 了( Ps: 你如果代码看的比较多,就会发现这个模式简直就是无处不再,太有用了), 触发按钮后通过代理,控制器类就会知道是哪一个按钮被点击了,很简单直接看代码:


#import
#import "CustomTarbar.h"@protocol CustomTarBarControllerDelegate;@interface CustomTabBarController : UIViewController
@property (nonatomic, strong) id delegate;
@property (nonatomic, strong) CustomTarbar *customTarbar;
@property (nonatomic, strong) NSMutableArray *viewControllers;
@property (nonatomic, strong) UIViewController *selectedViewController;
@property (nonatomic, strong) UIView *contentView;
@property (nonatomic) NSUInteger selectIndex;
@property (nonatomic) BOOL tabbarHidden;- (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated;@end@protocol CustomTarBarControllerDelegate
@optional
- (BOOL)tabBarController:(CustomTabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;- (void)tabBarController:(CustomTabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;@end

//
// CustomTabBarController.m
// CoolFrame
//
// Created by silicon on 2017/7/25.
// Copyright © 2017年 com.snailgames.coolframe. All rights reserved.
//#import "CustomTabBarController.h"
#import @interface CustomTabBarController ()@end@implementation CustomTabBarController
@synthesize delegate = _delegate;
@synthesize viewControllers = _viewControllers;
@synthesize selectIndex = _selectIndex;
@synthesize contentView = _contentView;
@synthesize customTarbar = _customTarbar;- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.self.title = @"CoolFrame";[self.view addSubview:[self contentView]];[self.view addSubview:[self customTarbar]];}- (void)viewWillAppear:(BOOL)animated{[super viewWillAppear:animated];[self setSelectIndex:[self selectIndex]];[[self customTarbar] setSelectedItem:[[self.customTarbar items] objectAtIndex:0]];[self setTabBarHidden:NO animated:NO];
}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}#pragma -meathod- (void)setViewControllers:(NSMutableArray *)viewControllers{if(viewControllers && [viewControllers isKindOfClass:[NSMutableArray class]]){_viewControllers = viewControllers;NSMutableArray *tabBarItems = [[NSMutableArray alloc] init];for (UIViewController *viewController in viewControllers) {CustomTabBarItem *tabBarItem = [[CustomTabBarItem alloc] init];[tabBarItem setTitle:viewController.title];[tabBarItems addObject:tabBarItem];}[[self customTarbar] setItems:tabBarItems];}
}- (UIViewController *)selectedViewController{return [self.viewControllers objectAtIndex:self.selectIndex];
}- (void)setSelectIndex:(NSUInteger)selectIndex{if(selectIndex > [self.viewControllers count]){return;}_selectIndex = selectIndex;if(_selectedViewController){[_selectedViewController willMoveToParentViewController:nil];[_selectedViewController.view removeFromSuperview];[_selectedViewController removeFromParentViewController];}[self setSelectedViewController:[self.viewControllers objectAtIndex:_selectIndex]];[self addChildViewController:self.selectedViewController];[[self selectedViewController].view setFrame:self.contentView.bounds];[self.contentView addSubview:self.selectedViewController.view];[self.selectedViewController didMoveToParentViewController:self];
}- (UIView *)contentView{if(!_contentView){_contentView = [[UIView alloc] init];[_contentView setBackgroundColor:[UIColor whiteColor]];[_contentView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];}return _contentView;
}- (CustomTarbar *)customTarbar{if(!_customTarbar){_customTarbar = [[CustomTarbar alloc] init];[_customTarbar setBackgroundColor:[UIColor clearColor]];[_customTarbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];_customTarbar.delegate = self;}return _customTarbar;
}- (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated{_tabbarHidden = hidden;CGSize viewSize = self.view.frame.size;CGFloat tabBarHeight = 49.0f;CGFloat tabBarY = viewSize.height;if(!hidden){tabBarY = viewSize.height - tabBarHeight;[[self customTarbar] setFrame:CGRectMake(0, tabBarY, viewSize.width, tabBarHeight)];[[self contentView] setFrame:CGRectMake(0, 0, viewSize.width, viewSize.height - tabBarHeight)];}}- (void)setTabbarHidden:(BOOL)tabbarHidden{[self setTabBarHidden:tabbarHidden animated:NO];
}#pragma -CustomTabbarDelegate- (BOOL)tabBar:(CustomTarbar *)tabBar shouldSelectItemAtIndex:(NSInteger)index{if (index > [self viewControllers].count) {return NO;}if([[self delegate] respondsToSelector:@selector(tabBarController:shouldSelectViewController:)]){if(![[self delegate] tabBarController:self shouldSelectViewController:[self viewControllers][index]]){return NO;}}if([self selectedViewController] == [self viewControllers][index]){if([[self selectedViewController] isKindOfClass:[UINavigationController class]]){UINavigationController *selectController = (UINavigationController *)[self selectedViewController];if([selectController topViewController] != [selectController viewControllers][0]){[selectController popToRootViewControllerAnimated:YES];return NO;}}return NO;}return YES;
}- (void)tabBar:(CustomTarbar *)tabBar didSelectItemAtIndex:(NSInteger)index{if(index <0 || index >&#61; [self viewControllers].count){return;}[self setSelectIndex:index];
}&#64;end

到这里&#xff0c;还缺一个导航栏&#xff0c;缺了咋办&#xff0c;咱们来给他加上不就完事了嘛&#xff01;首先定义一个类继承自 UINavigationBar &#xff0c;这个类我用于控制导航栏的大小&#xff0c;再创建一个继承自UINavigationController 的类&#xff0c;控制我们的界面为竖屏&#xff0c;具体的代码如下&#xff1a;

#import "CustomNavBar.h"&#64;implementation CustomNavBar{CGSize _previousSize;
}/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {// Drawing code
}
*/- (CGSize)sizeThatFits:(CGSize)size{size &#61; [super sizeThatFits:size];if([UIApplication sharedApplication].statusBarHidden){size.height &#61; 64;}return size;
}- (void)layoutSubviews{[super layoutSubviews];if(CGSizeEqualToSize(self.bounds.size, _previousSize)){_previousSize &#61; self.bounds.size;[self.layer removeAllAnimations];[self.layer.sublayers makeObjectsPerformSelector:&#64;selector(removeAllAnimations)];}}&#64;end

#import "CustomNavigationController.h"&#64;implementation CustomNavigationController- (BOOL)shouldAutorotate{return YES;
}- (UIInterfaceOrientationMask)supportedInterfaceOrientations{return UIInterfaceOrientationMaskPortrait;
}- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{return UIInterfaceOrientationPortrait;
}&#64;end

最后&#xff0c;把该需要的资源文件都导入到工程目录中来&#xff0c;在我们的AppDelegate 中设置好&#xff0c;AppDelegate 代码如下&#xff1a;

#import "AppDelegate.h"#import "CustomNavigationController.h"
#import "CustomNavBar.h"#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FouthViewController.h"#define NQFONT(v) [UIFont fontWithName:&#64;"HiraKakuProN-W3" size:v]
#define RGB(r, g, b) [UIColor colorWithRed:(r)/255.f green:(g)/255.f blue:(b)/255.f alpha:1.f]
&#64;interface AppDelegate ()&#64;property (nonatomic, strong) FirstViewController *firstViewController;
&#64;property (nonatomic, strong) SecondViewController *secondViewController;
&#64;property (nonatomic, strong) ThirdViewController *thirdViewController;
&#64;property (nonatomic, strong) FouthViewController *fouthViewController;
&#64;property (nonatomic, strong) CustomTabBarController *tabBarController;&#64;property (nonatomic, strong) CustomNavigationController *navController;&#64;end&#64;implementation AppDelegate- (void)setupViewControllers{if(!self.firstViewController){self.firstViewController &#61; [[FirstViewController alloc] init];}if(!self.secondViewController){self.secondViewController &#61; [[SecondViewController alloc] init];}if(!self.thirdViewController){self.thirdViewController &#61; [[ThirdViewController alloc] init];}if(!self.fouthViewController){self.fouthViewController &#61; [[FouthViewController alloc] init];}self.tabBarController &#61; [[CustomTabBarController alloc] init];NSMutableArray *viewsArray &#61; [[NSMutableArray alloc] initWithObjects:self.firstViewController,self.secondViewController,self.thirdViewController,self.fouthViewController, nil];[self.tabBarController setViewControllers:viewsArray];[self.tabBarController setSelectIndex:0];self.tabBarController.delegate &#61; self;[self customizeTabBarForController:_tabBarController];if(!_navController){_navController &#61; [[CustomNavigationController new] initWithNavigationBarClass:[CustomNavBar class] toolbarClass:[UIToolbar class]];[_navController pushViewController:_tabBarController animated:NO];}
}- (void)customizeTabBarForController:(CustomTabBarController *)tabBarController{UIImage *finishedImage &#61; [UIImage imageNamed:&#64;"tabbar_back_selected"];UIImage *unfinishedImage &#61; [UIImage imageNamed:&#64;"tabbar_back_normal"];NSArray *tabBarItemImages &#61; &#64;[&#64;"latest",&#64;"rank", &#64;"contest", &#64;"me"];NSArray *tabBarItemTitles &#61; &#64;[NSLocalizedString(&#64;"新闻", nil),NSLocalizedString(&#64;"直播", nil),NSLocalizedString(&#64;"发现", nil), NSLocalizedString(&#64;"我", nil)];NSInteger index &#61; 0;for (CustomTabBarItem *item in [[tabBarController customTarbar] items]){[item setBackgroundSelectedImage:finishedImage withUnselectedImage:unfinishedImage];UIImage *selectedimage &#61; [UIImage imageNamed:[tabBarItemImages objectAtIndex:index]];UIImage *unselectedimage &#61; [UIImage imageNamed:[tabBarItemImages objectAtIndex:index]];[item setFinishedSelectedImage:selectedimage withFinishedUnselectedImage:unselectedimage];[item setTitle:[tabBarItemTitles objectAtIndex:index]];item.unselectedTitleAttributes&#61; &#64;{NSFontAttributeName: NQFONT(10), NSForegroundColorAttributeName: RGB(255, 255, 255),};item.selectedTitleAttributes &#61; &#64;{NSFontAttributeName: NQFONT(10), NSForegroundColorAttributeName: RGB(255, 255, 255),};index&#43;&#43;;}
}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// Override point for customization after application launch.self.window &#61; [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];[self.window setBackgroundColor:[UIColor whiteColor]];[self setupViewControllers];[self.window setRootViewController:_navController];[self.window makeKeyAndVisible];return YES;
}


到这里&#xff0c;我们的开发就算完成了&#xff0c;一个简单的 App 界面框架就诞生了&#xff0c;在接下来的几篇文章中&#xff0c;我会对其不断的完善&#xff0c;加上更多新的东西&#xff0c;让其成为一个真正意义上的 App。

好了。祝大家生活愉快。多多收获友谊和爱情。如果想获取更多的讯息&#xff0c;请扫描下方二维码关注我的微信公众号&#xff1a;

这里写图片描述


推荐阅读
  • 开发技巧:在Interface Builder中实现UIButton文本居中对齐的方法与步骤
    开发技巧:在Interface Builder中实现UIButton文本居中对齐的方法与步骤 ... [详细]
  • 在尝试加载支持推送通知的iOS应用程序的Ad Hoc构建时,遇到了‘no valid aps-environment entitlement found for application’的错误提示。本文将探讨此错误的原因及多种可能的解决方案。 ... [详细]
  • 在软件开发过程中,经常需要将多个项目或模块进行集成和调试,尤其是当项目依赖于第三方开源库(如Cordova、CocoaPods)时。本文介绍了如何在Xcode中高效地进行多项目联合调试,分享了一些实用的技巧和最佳实践,帮助开发者解决常见的调试难题,提高开发效率。 ... [详细]
  • [译]  OS X 和 iOS 的测绘框架Core Plot 入门教程
    [译] OS X 和 iOS 的测绘框架Core Plot 入门教程 ... [详细]
  • Android 开发技巧:使用 AsyncTask 实现后台任务与 UI 交互
    本文详细介绍了如何在 Android 应用中利用 AsyncTask 来执行后台任务,并及时将任务进展反馈给用户界面,提高用户体验。 ... [详细]
  • 本文探讨了如何利用 Android 的 Movie 类来展示 GIF 动画,并详细介绍了调整 GIF 尺寸以适应不同布局的方法。同时,提供了相关的代码示例和注意事项。 ... [详细]
  • 本文详细介绍了如何使用C#实现不同类型的系统服务账户(如Windows服务、计划任务和IIS应用池)的密码重置方法。 ... [详细]
  • Vue CLI 基础入门指南
    本文详细介绍了 Vue CLI 的基础使用方法,包括环境搭建、项目创建、常见配置及路由管理等内容,适合初学者快速掌握 Vue 开发环境。 ... [详细]
  • 在1995年,Simon Plouffe 发现了一种特殊的求和方法来表示某些常数。两年后,Bailey 和 Borwein 在他们的论文中发表了这一发现,这种方法被命名为 Bailey-Borwein-Plouffe (BBP) 公式。该问题要求计算圆周率 π 的第 n 个十六进制数字。 ... [详细]
  • 二维码的实现与应用
    本文介绍了二维码的基本概念、分类及其优缺点,并详细描述了如何使用Java编程语言结合第三方库(如ZXing和qrcode.jar)来实现二维码的生成与解析。 ... [详细]
  • iOS 设备唯一标识获取的高效解决方案与实践
    在iOS 7中,苹果公司再次禁止了对MAC地址的访问,使得开发者无法直接获取设备的物理地址。为了在开发过程中实现设备的唯一标识,苹果推荐使用Keychain服务来存储和管理唯一的标识符。此外,还可以结合其他技术手段,如UUID和广告标识符(IDFA),以确保设备的唯一性和安全性。这些方法不仅能够满足应用的需求,还能保护用户的隐私。 ... [详细]
  • 如何高效利用 Xcode 中的断点功能进行调试
    在Xcode中,通过在特定条件触发时设置断点,可以在for循环中有效监控变量变化。例如,当循环次数达到预设值时,可通过断点调用`NSLog`函数输出当前迭代次数和相关变量值,如 `(void)NSLog(@"输出: %d", i);` 这样可以实时查看程序运行状态,便于快速定位和解决问题。 ... [详细]
  • 分享一下最近写的ReactNative的SSHSFTP组件,iOS端封装了NMSSH,Android端封装了JSch。支持SSH执行命令、实时Shell ... [详细]
  • 我正在尝试使SwiftUI中的按钮在文本旁边显示图像。但是,即使不在按钮中时图像 ... [详细]
  • OpenGL01 Mac 系统 OpenGL 环境配置
    直入主题(此环境配置在Mac下):1、xcode新创建MacOS工程,如下图2、添加 OpenGl.framework GLUT.framework两个系统库3、添加两个工具文件C ... [详细]
author-avatar
心雨1006600
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有