iOS 提示文字 类似微信拍摄小视频“手指不要放开”
2016-09-20 15:59
288 查看
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent
*)event
{
NSLog(@"touchesEnded");
UITouch *touch = [touches
anyObject];
CGPoint point = [touch
locationInView:self.view];
BOOL condition = [self
isInBtnRect:point];
/*
结束时候咱们设定有两种情况依然算录制成功
1.抬手时,录制时长 > 1/3总时长
2.录制进度条完成时,就算手指超出按钮范围也算录制成功 --
此时 end
方法不会调用,因为用户手指还在屏幕上,所以直接代码调用录制成功的方法,将控制器切换
*/
if (condition) {
NSLog(@"手指还在按钮范围之内");
if (self.progressWidth.constant
< SCREEN_WIDTH *
0.67) {
//录制完成
[self
recordComplete];
}else{
// showAtTop(@"手指不要放开");
// [ToastUtils showAtTop:[NSString stringWithFormat:@"ToastUtils"]];
[ToastUtils
showToast:[NSString
stringWithFormat:@"手指不要放开"]
atFrameY:SCREEN_HEIGHT -
130];
}
}
[self
stopAnimation];
self.changeBtn.hidden =
self.flashModelBtn.hidden =
NO;
}
+ (void)showToast:(NSString *)message atFrameY:(CGFloat)frameY{
[self
show:message atFrameY:frameY
showTime:2.0];
}
static UILabel *toastView =
nil;
+ (void)show:(NSString *)message atFrameY:(CGFloat)frameY showTime:(float)showTime{
if (![[NSThread
currentThread] isMainThread]) {
dispatch_async(dispatch_get_main_queue(), ^{
[self
show:message atFrameY:frameY
showTime:showTime];
});
return;
}
@synchronized(self){
if (toastView ==
nil) {
toastView = [[UILabel
alloc] init];
toastView.backgroundColor =
REDCOLOR;
toastView.textColor = [UIColor
whiteColor];
toastView.font = [UIFont
systemFontOfSize:17];
toastView.layer.masksToBounds =
YES;
toastView.layer.cornerRadius =
3.0f;
toastView.textAlignment =
NSTextAlignmentCenter;
toastView.alpha =
0;
toastView.numberOfLines =
0;
toastView.lineBreakMode =
NSLineBreakByCharWrapping;
[[UIApplication
sharedApplication].keyWindow
addSubview:toastView];
}
}
if (toastView.superview != [UIApplication
sharedApplication].keyWindow) {
[toastView
removeFromSuperview];
[[UIApplication
sharedApplication].keyWindow
addSubview:toastView];
}
// CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width;
CGFloat width = [self
stringText:message
font:18
isHeightFixed:YES
fixedValue:30];
CGFloat height =
30;
if (width >
screenWidth - 20) {
width = screenWidth -
20;
height = [self
stringText:message
font:18
isHeightFixed:NO
fixedValue:width];
}
CGRect frame =
CGRectMake(([UIScreen
mainScreen].bounds.size.width-width)/2,frameY,
width, height);
toastView.alpha =
1;
toastView.text = message;
toastView.frame = frame;
[UIView
animateWithDuration:showTime
animations:^{
toastView.alpha =
0;
} completion:^(BOOL finished) {
}];
}
//根据字符串长度获取对应的宽度或者高度
+ (CGFloat)stringText:(NSString *)text font:(CGFloat)font isHeightFixed:(BOOL)isHeightFixed
fixedValue:(CGFloat)fixedValue
{
CGSize size;
if (isHeightFixed) {
size = CGSizeMake(MAXFLOAT, fixedValue);
} else {
size = CGSizeMake(fixedValue,
MAXFLOAT);
}
CGSize resultSize;
//返回计算出的size
resultSize = [text boundingRectWithSize:size
options:NSStringDrawingTruncatesLastVisibleLine |
NSStringDrawingUsesFontLeading |
NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName: [UIFont
systemFontOfSize:font]}
context:nil].size;
if (isHeightFixed) {
return resultSize.width;
} else {
return resultSize.height;
}
}
*)event
{
NSLog(@"touchesEnded");
UITouch *touch = [touches
anyObject];
CGPoint point = [touch
locationInView:self.view];
BOOL condition = [self
isInBtnRect:point];
/*
结束时候咱们设定有两种情况依然算录制成功
1.抬手时,录制时长 > 1/3总时长
2.录制进度条完成时,就算手指超出按钮范围也算录制成功 --
此时 end
方法不会调用,因为用户手指还在屏幕上,所以直接代码调用录制成功的方法,将控制器切换
*/
if (condition) {
NSLog(@"手指还在按钮范围之内");
if (self.progressWidth.constant
< SCREEN_WIDTH *
0.67) {
//录制完成
[self
recordComplete];
}else{
// showAtTop(@"手指不要放开");
// [ToastUtils showAtTop:[NSString stringWithFormat:@"ToastUtils"]];
[ToastUtils
showToast:[NSString
stringWithFormat:@"手指不要放开"]
atFrameY:SCREEN_HEIGHT -
130];
}
}
[self
stopAnimation];
self.changeBtn.hidden =
self.flashModelBtn.hidden =
NO;
}
+ (void)showToast:(NSString *)message atFrameY:(CGFloat)frameY{
[self
show:message atFrameY:frameY
showTime:2.0];
}
static UILabel *toastView =
nil;
+ (void)show:(NSString *)message atFrameY:(CGFloat)frameY showTime:(float)showTime{
if (![[NSThread
currentThread] isMainThread]) {
dispatch_async(dispatch_get_main_queue(), ^{
[self
show:message atFrameY:frameY
showTime:showTime];
});
return;
}
@synchronized(self){
if (toastView ==
nil) {
toastView = [[UILabel
alloc] init];
toastView.backgroundColor =
REDCOLOR;
toastView.textColor = [UIColor
whiteColor];
toastView.font = [UIFont
systemFontOfSize:17];
toastView.layer.masksToBounds =
YES;
toastView.layer.cornerRadius =
3.0f;
toastView.textAlignment =
NSTextAlignmentCenter;
toastView.alpha =
0;
toastView.numberOfLines =
0;
toastView.lineBreakMode =
NSLineBreakByCharWrapping;
[[UIApplication
sharedApplication].keyWindow
addSubview:toastView];
}
}
if (toastView.superview != [UIApplication
sharedApplication].keyWindow) {
[toastView
removeFromSuperview];
[[UIApplication
sharedApplication].keyWindow
addSubview:toastView];
}
// CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width;
CGFloat width = [self
stringText:message
font:18
isHeightFixed:YES
fixedValue:30];
CGFloat height =
30;
if (width >
screenWidth - 20) {
width = screenWidth -
20;
height = [self
stringText:message
font:18
isHeightFixed:NO
fixedValue:width];
}
CGRect frame =
CGRectMake(([UIScreen
mainScreen].bounds.size.width-width)/2,frameY,
width, height);
toastView.alpha =
1;
toastView.text = message;
toastView.frame = frame;
[UIView
animateWithDuration:showTime
animations:^{
toastView.alpha =
0;
} completion:^(BOOL finished) {
}];
}
//根据字符串长度获取对应的宽度或者高度
+ (CGFloat)stringText:(NSString *)text font:(CGFloat)font isHeightFixed:(BOOL)isHeightFixed
fixedValue:(CGFloat)fixedValue
{
CGSize size;
if (isHeightFixed) {
size = CGSizeMake(MAXFLOAT, fixedValue);
} else {
size = CGSizeMake(fixedValue,
MAXFLOAT);
}
CGSize resultSize;
//返回计算出的size
resultSize = [text boundingRectWithSize:size
options:NSStringDrawingTruncatesLastVisibleLine |
NSStringDrawingUsesFontLeading |
NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName: [UIFont
systemFontOfSize:font]}
context:nil].size;
if (isHeightFixed) {
return resultSize.width;
} else {
return resultSize.height;
}
}
相关文章推荐
- MessageDisplayKit 一个类似微信App的IM应用,拥有发送文字、图片、语音、视频、地理位置消息,管理本地通信录、分享朋友圈、漂流交友、摇一摇和更多有趣的功能。
- ios仿微信短视频拍摄类库WechatShortVideo
- iOS - 自主实现类似微信语音视频信息聊天 (idoubs详细使用方法)1.0
- iOS 视频拍摄与压缩
- 【iOS开发】设置textView的默认提示文字
- IOS 类似聊天框自动适应文字背景图片的设置
- 类似微信发送视频的流程
- iOS视频拍摄与压缩
- 【iOS开发】设置textView的默认提示文字,也就是textView变相的"placeholder"。
- iOS自定义相机界面,实现微信小视频UI效果
- 使用php发送自定义背景、头像、文字的二维码海报并带有提示的微信消息
- 关于移动端input框 在微信中 和ios中无法输入文字的问题
- 请大家不要发表与奥运会相抵触的文字、图片、视频及非法版权的任何内容
- [IOS]获取网页上数据(图片、文字、视频)
- iOS 二维码ZBarSDK类似微信的扫一扫
- ios设备突破微信小视频6S限制的方法
- 抽奖滚动文字如何透明地覆盖在动态视频背景上?-活动现场双屏管理系统操作提示
- iphone ios 视频拍摄旋转
- iOS视频拍摄压缩上传和播放
- IOS开发—iOS视频拍摄与压缩