标签:
//
// ViewController.m
// block_chuanzhi
//
// Created by imac on 15-4-1.
// Copyright (c) 2015年 imac. All rights reserved.
//
#import "ViewController.h"
#import "InputView.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *labelText;
- (IBAction)btnAction:(UIButton *)sender;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)btnAction:(UIButton *)sender {
InputView *inputView = [[InputView alloc] init];
inputView.block = ^(NSString *text)
{
_labelText.text = text;
};
[inputView show];
}
@end
————————————————————————————————————————————————————————————
——————————————————————————————————————————————————————————————
#import <UIKit/UIKit.h>
typedef void(^InputBlock)(NSString *);
@interface InputView : UIView
@property (nonatomic , copy)InputBlock block;
- (void)show;
@end
——————————————————————————————————————————————————————————————
——————————————————————————————————————————————————————————————
//
// InputView.m
// block_chuanzhi
//
// Created by imac on 15-4-1.
// Copyright (c) 2015年 imac. All rights reserved.
//
#import "InputView.h"
#define kSceenWidth self.bounds.size.width
#define kSceenHeight self.bounds.size.width
@implementation InputView
{
UITextView *_textView;
}
- (id)initWithFrame:(CGRect)frame
{
frame = CGRectMake(25, 20, 300, 300);
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor orangeColor];
self.layer.cornerRadius = 5;
self.layer.borderWidth = 2;
self.layer.borderColor = [UIColor redColor].CGColor;
// 设置阴影颜色
self.layer.shadowColor = [UIColor blackColor].CGColor;
// 设置引用的透明度
self.layer.shadowOpacity = 0.7;
// 设置阴影的偏移量
self.layer.shadowOffset = CGSizeMake(20, 20);
_textView = [[UITextView alloc] initWithFrame:CGRectMake((kSceenWidth - 280)/ 2, 10, 280, 200)];
[_textView becomeFirstResponder];
[self addSubview:_textView];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake((kSceenWidth - 100) / 2, kSceenHeight - 30, 100, 30);
[btn setTitle:@"sender" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:btn];
}
return self;
}
- (void)btnAction:(UIButton *)btn
{
if (_block != nil) {
_block(_textView.text);
}
[self removeFromSuperview];
}
- (void)show
{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
//设置动画
self.transform = CGAffineTransformMakeScale(.7, .7);
[UIView animateWithDuration:.5
animations:^{
self.transform = CGAffineTransformMakeScale(1.1, 1.1);
} completion:^(BOOL finished) {
if (finished) {
[UIView animateWithDuration:.5 animations:^{
self.transform = CGAffineTransformIdentity;
}];
}
}];
[window addSubview:self];
}
@end
标签:
原文地址:http://www.cnblogs.com/zhangxi1017/p/4383773.html