iOS开发-自定义UIAlterView(iOS 7)

App中不可能少了弹框,弹框是交互的必要形式,使用起来也非常简单,不过最近需要自定义一个弹框,虽然iOS本身的弹框已经能满足大部分的需求,但是不可避免还是需要做一些自定义的工作。iOS7之前是可以自定义AlterView的,就是继承一下UIAlterView,然后初始化的时候通过addSubview添加自定义的View,但是iOS7之后这样做就不行了,不过还好有开源项目可以解决这个问题。

iOS默认弹框

viewDidLoad中添加两个按钮,代码如下:

 

    UIButton  *orignalBtn=[[UIButton alloc]initWithFrame:CGRectMake(100, 40, 100, 50)];[orignalBtn setBackgroundColor:[UIColor greenColor]];[orignalBtn setTitle:@"iOS弹框" forState:UIControlStateNormal];[orignalBtn addTarget:self action:@selector(orignalShow) forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:orignalBtn];UIButton  *customlBtn=[[UIButton alloc]initWithFrame:CGRectMake(100, 140, 100, 50)];[customlBtn setBackgroundColor:[UIColor redColor]];[customlBtn setTitle:@"自定义弹框" forState:UIControlStateNormal];[customlBtn addTarget:self action:@selector(customShow) forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:customlBtn];

 

 响应默认弹框事件:

-(void)orignalShow{UIAlertView *alterView=[[UIAlertView alloc]initWithTitle:@"提示" message:@"博客园-Fly_Elephant" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];[alterView show];
}

  效果如下:

 

自定义弹框

主要解决iOS7之后的系统无法自定义弹框的问题,使用开源项目,项目地址:https://github.com/wimagguc/ios-custom-alertview,其实就是自定义了一个类:

CustomIOSAlertView.h

#import <UIKit/UIKit.h>@protocol CustomIOSAlertViewDelegate- (void)customIOS7dialogButtonTouchUpInside:(id)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;@end@interface CustomIOSAlertView : UIView<CustomIOSAlertViewDelegate>@property (nonatomic, retain) UIView *parentView;    // The parent view this 'dialog' is attached to
@property (nonatomic, retain) UIView *dialogView;    // Dialog's container view
@property (nonatomic, retain) UIView *containerView; // Container within the dialog (place your ui elements here)@property (nonatomic, assign) id<CustomIOSAlertViewDelegate> delegate;
@property (nonatomic, retain) NSArray *buttonTitles;
@property (nonatomic, assign) BOOL useMotionEffects;@property (copy) void (^onButtonTouchUpInside)(CustomIOSAlertView *alertView, int buttonIndex) ;- (id)init;/*!DEPRECATED: Use the [CustomIOSAlertView init] method without passing a parent view.*/
- (id)initWithParentView: (UIView *)_parentView __attribute__ ((deprecated));- (void)show;
- (void)close;- (IBAction)customIOS7dialogButtonTouchUpInside:(id)sender;
- (void)setOnButtonTouchUpInside:(void (^)(CustomIOSAlertView *alertView, int buttonIndex))onButtonTouchUpInside;- (void)deviceOrientationDidChange: (NSNotification *)notification;
- (void)dealloc;@end

CustomIOSAlertView.m

#import "CustomIOSAlertView.h"
#import <QuartzCore/QuartzCore.h>const static CGFloat kCustomIOSAlertViewDefaultButtonHeight       = 50;
const static CGFloat kCustomIOSAlertViewDefaultButtonSpacerHeight = 1;
const static CGFloat kCustomIOSAlertViewCornerRadius              = 7;
const static CGFloat kCustomIOS7MotionEffectExtent                = 10.0;@implementation CustomIOSAlertViewCGFloat buttonHeight = 0;
CGFloat buttonSpacerHeight = 0;@synthesize parentView, containerView, dialogView, onButtonTouchUpInside;
@synthesize delegate;
@synthesize buttonTitles;
@synthesize useMotionEffects;- (id)initWithParentView: (UIView *)_parentView
{self = [self init];if (_parentView) {self.frame = _parentView.frame;self.parentView = _parentView;}return self;
}- (id)init
{self = [super init];if (self) {self.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);delegate = self;useMotionEffects = false;buttonTitles = @[@"Close"];[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];}return self;
}// Create the dialog view, and animate opening the dialog
- (void)show
{dialogView = [self createContainerView];dialogView.layer.shouldRasterize = YES;dialogView.layer.rasterizationScale = [[UIScreen mainScreen] scale];self.layer.shouldRasterize = YES;self.layer.rasterizationScale = [[UIScreen mainScreen] scale];#if (defined(__IPHONE_7_0))if (useMotionEffects) {[self applyMotionEffects];}
#endifself.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];[self addSubview:dialogView];// Can be attached to a view or to the top most window// Attached to a view:if (parentView != NULL) {[parentView addSubview:self];// Attached to the top most window} else {// On iOS7, calculate with orientationif (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];switch (interfaceOrientation) {case UIInterfaceOrientationLandscapeLeft:self.transform = CGAffineTransformMakeRotation(M_PI * 270.0 / 180.0);break;case UIInterfaceOrientationLandscapeRight:self.transform = CGAffineTransformMakeRotation(M_PI * 90.0 / 180.0);break;case UIInterfaceOrientationPortraitUpsideDown:self.transform = CGAffineTransformMakeRotation(M_PI * 180.0 / 180.0);break;default:break;}[self setFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];// On iOS8, just place the dialog in the middle} else {CGSize screenSize = [self countScreenSize];CGSize dialogSize = [self countDialogSize];CGSize keyboardSize = CGSizeMake(0, 0);dialogView.frame = CGRectMake((screenSize.width - dialogSize.width) / 2, (screenSize.height - keyboardSize.height - dialogSize.height) / 2, dialogSize.width, dialogSize.height);}[[[[UIApplication sharedApplication] windows] firstObject] addSubview:self];}dialogView.layer.opacity = 0.5f;dialogView.layer.transform = CATransform3DMakeScale(1.3f, 1.3f, 1.0);[UIView animateWithDuration:0.2f delay:0.0 options:UIViewAnimationOptionCurveEaseInOutanimations:^{self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4f];dialogView.layer.opacity = 1.0f;dialogView.layer.transform = CATransform3DMakeScale(1, 1, 1);}completion:NULL];}// Button has been touched
- (IBAction)customIOS7dialogButtonTouchUpInside:(id)sender
{if (delegate != NULL) {[delegate customIOS7dialogButtonTouchUpInside:self clickedButtonAtIndex:[sender tag]];}if (onButtonTouchUpInside != NULL) {onButtonTouchUpInside(self, (int)[sender tag]);}
}// Default button behaviour
- (void)customIOS7dialogButtonTouchUpInside: (CustomIOSAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{NSLog(@"Button Clicked! %d, %d", (int)buttonIndex, (int)[alertView tag]);[self close];
}// Dialog close animation then cleaning and removing the view from the parent
- (void)close
{CATransform3D currentTransform = dialogView.layer.transform;if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {CGFloat startRotation = [[dialogView valueForKeyPath:@"layer.transform.rotation.z"] floatValue];CATransform3D rotation = CATransform3DMakeRotation(-startRotation + M_PI * 270.0 / 180.0, 0.0f, 0.0f, 0.0f);dialogView.layer.transform = CATransform3DConcat(rotation, CATransform3DMakeScale(1, 1, 1));}dialogView.layer.opacity = 1.0f;[UIView animateWithDuration:0.2f delay:0.0 options:UIViewAnimationOptionTransitionNoneanimations:^{self.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.0f];dialogView.layer.transform = CATransform3DConcat(currentTransform, CATransform3DMakeScale(0.6f, 0.6f, 1.0));dialogView.layer.opacity = 0.0f;}completion:^(BOOL finished) {for (UIView *v in [self subviews]) {[v removeFromSuperview];}[self removeFromSuperview];}];
}- (void)setSubView: (UIView *)subView
{containerView = subView;
}// Creates the container view here: create the dialog, then add the custom content and buttons
- (UIView *)createContainerView
{if (containerView == NULL) {containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 150)];}CGSize screenSize = [self countScreenSize];CGSize dialogSize = [self countDialogSize];// For the black background[self setFrame:CGRectMake(0, 0, screenSize.width, screenSize.height)];// This is the dialog's container; we attach the custom content and the buttons to this oneUIView *dialogContainer = [[UIView alloc] initWithFrame:CGRectMake((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2, dialogSize.width, dialogSize.height)];// First, we style the dialog to match the iOS7 UIAlertView >>>CAGradientLayer *gradient = [CAGradientLayer layer];gradient.frame = dialogContainer.bounds;gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:218.0/255.0 green:218.0/255.0 blue:218.0/255.0 alpha:1.0f] CGColor],(id)[[UIColor colorWithRed:233.0/255.0 green:233.0/255.0 blue:233.0/255.0 alpha:1.0f] CGColor],(id)[[UIColor colorWithRed:218.0/255.0 green:218.0/255.0 blue:218.0/255.0 alpha:1.0f] CGColor],nil];CGFloat cornerRadius = kCustomIOSAlertViewCornerRadius;gradient.cornerRadius = cornerRadius;[dialogContainer.layer insertSublayer:gradient atIndex:0];dialogContainer.layer.cornerRadius = cornerRadius;dialogContainer.layer.borderColor = [[UIColor colorWithRed:198.0/255.0 green:198.0/255.0 blue:198.0/255.0 alpha:1.0f] CGColor];dialogContainer.layer.borderWidth = 1;dialogContainer.layer.shadowRadius = cornerRadius + 5;dialogContainer.layer.shadowOpacity = 0.1f;dialogContainer.layer.shadowOffset = CGSizeMake(0 - (cornerRadius+5)/2, 0 - (cornerRadius+5)/2);dialogContainer.layer.shadowColor = [UIColor blackColor].CGColor;dialogContainer.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:dialogContainer.bounds cornerRadius:dialogContainer.layer.cornerRadius].CGPath;// There is a line above the buttonUIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, dialogContainer.bounds.size.height - buttonHeight - buttonSpacerHeight, dialogContainer.bounds.size.width, buttonSpacerHeight)];lineView.backgroundColor = [UIColor colorWithRed:198.0/255.0 green:198.0/255.0 blue:198.0/255.0 alpha:1.0f];[dialogContainer addSubview:lineView];// ^^^// Add the custom container if there is any[dialogContainer addSubview:containerView];// Add the buttons too[self addButtonsToView:dialogContainer];return dialogContainer;
}// Helper function: add buttons to container
- (void)addButtonsToView: (UIView *)container
{if (buttonTitles==NULL) { return; }CGFloat buttonWidth = container.bounds.size.width / [buttonTitles count];for (int i=0; i<[buttonTitles count]; i++) {UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];[closeButton setFrame:CGRectMake(i * buttonWidth, container.bounds.size.height - buttonHeight, buttonWidth, buttonHeight)];[closeButton addTarget:self action:@selector(customIOS7dialogButtonTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];[closeButton setTag:i];[closeButton setTitle:[buttonTitles objectAtIndex:i] forState:UIControlStateNormal];[closeButton setTitleColor:[UIColor colorWithRed:0.0f green:0.5f blue:1.0f alpha:1.0f] forState:UIControlStateNormal];[closeButton setTitleColor:[UIColor colorWithRed:0.2f green:0.2f blue:0.2f alpha:0.5f] forState:UIControlStateHighlighted];[closeButton.titleLabel setFont:[UIFont boldSystemFontOfSize:14.0f]];[closeButton.layer setCornerRadius:kCustomIOSAlertViewCornerRadius];[container addSubview:closeButton];}
}// Helper function: count and return the dialog's size
- (CGSize)countDialogSize
{CGFloat dialogWidth = containerView.frame.size.width;CGFloat dialogHeight = containerView.frame.size.height + buttonHeight + buttonSpacerHeight;return CGSizeMake(dialogWidth, dialogHeight);
}// Helper function: count and return the screen's size
- (CGSize)countScreenSize
{if (buttonTitles!=NULL && [buttonTitles count] > 0) {buttonHeight       = kCustomIOSAlertViewDefaultButtonHeight;buttonSpacerHeight = kCustomIOSAlertViewDefaultButtonSpacerHeight;} else {buttonHeight = 0;buttonSpacerHeight = 0;}CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;// On iOS7, screen width and height doesn't automatically follow orientationif (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {CGFloat tmp = screenWidth;screenWidth = screenHeight;screenHeight = tmp;}}return CGSizeMake(screenWidth, screenHeight);
}#if (defined(__IPHONE_7_0))
// Add motion effects
- (void)applyMotionEffects {if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {return;}UIInterpolatingMotionEffect *horizontalEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x"type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];horizontalEffect.minimumRelativeValue = @(-kCustomIOS7MotionEffectExtent);horizontalEffect.maximumRelativeValue = @( kCustomIOS7MotionEffectExtent);UIInterpolatingMotionEffect *verticalEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y"type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];verticalEffect.minimumRelativeValue = @(-kCustomIOS7MotionEffectExtent);verticalEffect.maximumRelativeValue = @( kCustomIOS7MotionEffectExtent);UIMotionEffectGroup *motionEffectGroup = [[UIMotionEffectGroup alloc] init];motionEffectGroup.motionEffects = @[horizontalEffect, verticalEffect];[dialogView addMotionEffect:motionEffectGroup];
}
#endif- (void)dealloc
{[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
}// Rotation changed, on iOS7
- (void)changeOrientationForIOS7 {UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];CGFloat startRotation = [[self valueForKeyPath:@"layer.transform.rotation.z"] floatValue];CGAffineTransform rotation;switch (interfaceOrientation) {case UIInterfaceOrientationLandscapeLeft:rotation = CGAffineTransformMakeRotation(-startRotation + M_PI * 270.0 / 180.0);break;case UIInterfaceOrientationLandscapeRight:rotation = CGAffineTransformMakeRotation(-startRotation + M_PI * 90.0 / 180.0);break;case UIInterfaceOrientationPortraitUpsideDown:rotation = CGAffineTransformMakeRotation(-startRotation + M_PI * 180.0 / 180.0);break;default:rotation = CGAffineTransformMakeRotation(-startRotation + 0.0);break;}[UIView animateWithDuration:0.2f delay:0.0 options:UIViewAnimationOptionTransitionNoneanimations:^{dialogView.transform = rotation;}completion:nil];}// Rotation changed, on iOS8
- (void)changeOrientationForIOS8: (NSNotification *)notification {CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;[UIView animateWithDuration:0.2f delay:0.0 options:UIViewAnimationOptionTransitionNoneanimations:^{CGSize dialogSize = [self countDialogSize];CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;self.frame = CGRectMake(0, 0, screenWidth, screenHeight);dialogView.frame = CGRectMake((screenWidth - dialogSize.width) / 2, (screenHeight - keyboardSize.height - dialogSize.height) / 2, dialogSize.width, dialogSize.height);}completion:nil];}// Handle device orientation changes
- (void)deviceOrientationDidChange: (NSNotification *)notification
{// If dialog is attached to the parent view, it probably wants to handle the orientation change itselfif (parentView != NULL) {return;}if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {[self changeOrientationForIOS7];} else {[self changeOrientationForIOS8:notification];}
}// Handle keyboard show/hide changes
- (void)keyboardWillShow: (NSNotification *)notification
{CGSize screenSize = [self countScreenSize];CGSize dialogSize = [self countDialogSize];CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {CGFloat tmp = keyboardSize.height;keyboardSize.height = keyboardSize.width;keyboardSize.width = tmp;}[UIView animateWithDuration:0.2f delay:0.0 options:UIViewAnimationOptionTransitionNoneanimations:^{dialogView.frame = CGRectMake((screenSize.width - dialogSize.width) / 2, (screenSize.height - keyboardSize.height - dialogSize.height) / 2, dialogSize.width, dialogSize.height);}completion:nil];
}- (void)keyboardWillHide: (NSNotification *)notification
{CGSize screenSize = [self countScreenSize];CGSize dialogSize = [self countDialogSize];[UIView animateWithDuration:0.2f delay:0.0 options:UIViewAnimationOptionTransitionNoneanimations:^{dialogView.frame = CGRectMake((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2, dialogSize.width, dialogSize.height);}completion:nil];
}@end

调用代码:

-(void)customShow{CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];[alertView setContainerView:[self customView]];[alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"取消", @"确定", nil]];[alertView setDelegate:self];[alertView setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) {NSString *result=alertView.buttonTitles[buttonIndex];NSLog(@"点击了%@按钮",result);[alertView close];}];[alertView setUseMotionEffects:true];[alertView show];}- (UIView *)customView
{UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 240, 160)];UILabel *tip=[[UILabel alloc]initWithFrame:CGRectMake(100, 10, 50, 30)];[tip setText:@"提示"];[customView addSubview:tip];UILabel *content=[[UILabel alloc]initWithFrame:CGRectMake(10, 60, 210, 30)];[content setText:@"http://www.cnblogs.com/xiaofeixiang"];[content setFont:[UIFont systemFontOfSize:12]];[customView addSubview:content];return customView;
}

 效果如下:

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/544966.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Spring 事务失效的 8 大场景,面试官直呼666...

前几天发了一篇文章里面有一个关于事务失效的问题&#xff1a;用 Spring 的 Transactional 注解控制事务有哪些不生效的场景&#xff1f;其中有个热心粉丝留言分享了下&#xff0c;我觉得总结得有点经验&#xff0c;给置顶了&#xff1a;但是我觉得还是总结得不够全&#xff0c…

认真聊一下MySQL索引的底层实现!

前言当我们发现SQL执行很慢的时候&#xff0c;自然而然想到的就是加索引&#xff0c;当然他也是高频的面试问题&#xff0c;所以今天我们一起来学习一下MySQL索引的底层实现&#xff1a;B树。树简介、树种类B-树、B树简介B树插入B树查找B树删除B树经典面试题树的简介树的简介树…

最新大厂面试真题集锦

年后又是一波求职季&#xff0c;正是“金三银四”这个求职黄金期&#xff0c;很多人扎堆在这个时间段跳槽&#xff0c;找工作&#xff0c;程序员也不例外。春节刚过&#xff0c;各公司企业都开始启动了新一年的招聘计划&#xff0c;招聘岗位倍增&#xff0c;求职人数远超于岗位…

使用OpenCV在Python中进行人脸和眼睛检测

Modules Used: 使用的模块&#xff1a; python-opencv(cv2)python-opencv(cv2) python-opencv(cv2) Opencv(Open source computer vision) is a python library that will help us to solve computer vision problems. Opencv(开源计算机视觉)是一个Python库&#xff0c;可帮…

Java打造一款SSH客户端,已开源!

最近由于项目需求&#xff0c;项目中需要实现一个WebSSH连接终端的功能&#xff0c;由于自己第一次做这类型功能&#xff0c;所以首先上了GitHub找了找有没有现成的轮子可以拿来直接用&#xff0c;当时看到了很多这方面的项目&#xff0c;例如&#xff1a;GateOne、webssh、she…

我去,这几个Linux指令太装B了|动图展示

1. sl先看一下呼啸而过的火车&#xff1b;安装指令如下&#xff1b;sduo apt-get install sl执行结果如下&#xff1a;2. htop图形化Linux系统性能监测工具&#xff0c;屌不屌:安装指令如下:sduo apt-get install htop执行结果如下&#xff1b;3. gcp以前用cp复制文件总是看不懂…

书店POS机--细化迭代2--测试

2019独角兽企业重金招聘Python工程师标准>>> (1) 开始一次新的销售&#xff0c;点击书店POS系统的销售&#xff1a; (2) 进入销售模块之后的界面如下&#xff1a; (3)逐条录入商品条目(根据商品编号)&#xff0c;并修改数量。确认无误之后点击“确认”按钮&#x…

Google Guava,牛逼的脚手架

01、前世今生你好呀&#xff0c;我是 Guava。1995 年的时候&#xff0c;我的“公明”哥哥——Java 出生了。经过 20 年的发展&#xff0c;他已经成为世界上最流行的编程语言了&#xff0c;请允许我有失公允的把“之一”给去了。虽然他时常遭受着各种各样的吐槽&#xff0c;但他…

阿里巴巴Druid,轻松实现MySQL数据库加密!

作者 | 王磊来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;为什么要加密&#xff1f;现在的开发习惯&#xff0c;无论是公司的项目还是个人的项目&#xff0c;都会选择将源码上传到 Gi…

计算机图形学图形旋转_计算机图形学中的平板显示

计算机图形学图形旋转平板显示器 (Flat Panel Display) It is generally known as FPD, the flat-panel display is such a display technology which overtakes Cathode Ray Tube as a new standard of computer desktop displays. Unlike monitors through CRT, flat-panel d…

一文掌握Redisson分布式锁原理|干货推荐

ReentrantLock 重入锁在说 Redisson 之前我们先来说一下 JDK 可重入锁: ReentrantLockReentrantLock 保证了 JVM 共享资源同一时刻只允许单个线程进行操作实现思路ReentrantLock 内部公平锁与非公平锁继承了 AQS[AbstractQueuedSynchronizer]1、AQS 内部通过 volatil 修饰的 in…

7种分布式事务的解决方案,一次讲给你听

本文约5300字&#xff0c;阅读时长「5分钟」什么是分布式事务分布式事务是指事务的参与者、支持事务的服务器、资源服务器以及事务管理器「分别位于不同的分布式系统的不同节点之上」。一个大的操作由N多的小的操作共同完成。而这些小的操作又分布在不同的服务上。针对于这些操…

css @media 响应式布局

2019独角兽企业重金招聘Python工程师标准>>> &#xfeff;1、在 html 标签中 <link rel"stylesheet" type"text/css" href"style1.css" media"screen and (min-width: 600px) and (max-width: 800px)"> 2、在样式表中…

Apache JK Tomcat 集群问题

2019独角兽企业重金招聘Python工程师标准>>> 这几天被集群并发问题快折腾死了&#xff0c;望哪位高人看下到底是哪里出现了问题。 Apache Server是正常的&#xff0c;各服务器的Tomcat 也是正常的&#xff0c;但当Apache的连接数达到 300左右的时候&#xff0c;JK就…

Redis实现分布式锁的7种方案,及正确使用姿势!

种方案前言日常开发中&#xff0c;秒杀下单、抢红包等等业务场景&#xff0c;都需要用到分布式锁。而Redis非常适合作为分布式锁使用。本文将分七个方案展开&#xff0c;跟大家探讨Redis分布式锁的正确使用方式。如果有不正确的地方&#xff0c;欢迎大家指出哈&#xff0c;一起…

Android软件开发之盘点所有Dialog对话框大合集(一)

转&#xff1a;http://xys289187120.blog.51cto.com/3361352/657562/ 雨松MOMO带大家盘点Android 中的对话框 今天我用自己写的一个Demo 和大家详细介绍一个Android中的对话框的使用技巧。 1.确定取消对话框 对话框中有2个按钮 通过调用 setPositiveButton 方法 和 setNegat…

PHP将数组存入数据库中的四种方式

PHP将数组存入数据库中的四种方式 最近突然遇到了一个问题&#xff0c;如何用PHP将数组存入到数据库中&#xff0c;经过自己的多方查找和研究&#xff0c;总结了以下四种方法&#xff1a;1.implode()和explode()方式2.print_r()和自定义函数方式3.serialize()和unserialize()方…

Android开发:利用Activity的Dialog风格完成弹出框设计

转&#xff1a;http://www.linuxidc.com/Linux/2011-08/41933.htm 在我们使用Dialog时&#xff0c;如果需要用到很多自己设计的控件&#xff0c;虽然可以让弹出框显示出我们需要的界面&#xff0c;但却无法找到地方完成控制代码的编写&#xff0c;如何解决这个问题呢,我们可以将…

Java中实现定时任务的3种方法!

今天我们不用任何框架&#xff0c;用最朴素的 Java API 来实现定时任务&#xff0c;本文会介绍 3 种实现方案&#xff0c;我们一起来看...1、 sleep 这也是我们最常用的 sleep 休眠大法&#xff0c;不只是当作休眠用&#xff0c;我们还可以利用它很轻松的能实现一个简单的定时任…

回文子序列_计算回文子序列的总数

回文子序列Problem statement: 问题陈述&#xff1a; Given a string str, find total number of possible palindromic sub-sequences. A sub-sequence does not need to be consecutive, but for any xixj i<j must be valid in the parent string too. Like "icl&q…