IOS研究院之打开照相机与本地相册选择图片(一)

2014-11-23 22:30:42 ? 作者: ? 浏览: 13
如下图所示 在本地相册中选择一张图片后,我们将他拷贝至沙盒当中,在客户端中将它的缩略图放在按钮旁边,这个结构其实和新浪微薄中选择图片后的效果一样。最终点击发送将按钮将图片2进制图片上传服务器。
下面我们仔细学习具体的细节。创建一个空的 IOS项目,接着在创建一个ViewController。
AppDelegate.h 应用的代理类 这个没什么好说的就是直接打开刚刚创建的新ViewController。
1
#import
2
#import "TestViewController.h"
3
4
@interface AppDelegate : UIResponder
5
6
@property (strong, nonatomic) UIWindow *window;
7
@property (strong, nonatomic) UINavigationController *navController;
8
@property (strong, nonatomic) UIViewController *viewController;
9
@end
AppDelegate.m 在这里就是打开我们创建的TestViewController
01
#import "AppDelegate.h"
02
03
@implementation AppDelegate
04
05
@synthesize window = _window;
06
@synthesize navController;
07
@synthesize viewController;
08
09
- (void)dealloc
10
{
11
[_window release];
12
[super dealloc];
13
}
14
15
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
16
{
17
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
18
19
self.window.backgroundColor = [UIColor whiteColor];
20
self.viewController = [[TestViewController alloc]init];
21
self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
22
[self.window addSubview:navController.view];
23
24
[self.window makeKeyAndVisible];
25
return YES;
26
}
27
28
@end
TestViewController.h 注意这里面引入了很多代理类。
01
#import
02
03
@interface TestViewController : UIViewController
04
{
05
//输入框
06
UITextView *_textEditor;
07
08
//下拉菜单
09
UIActionSheet *myActionSheet;
10
11
//图片2进制路径
12
NSString* filePath;
13
}
14
@end
TestViewController.m 请大家仔细看这个类, 所有的东西都写在了这里哈。
001
#import "TestViewController.h"
002
003
@interface TestViewController ()
004
005
@end
006
007
@implementation TestViewController
008
009
- (void)viewDidLoad
010
{
011
[super viewDidLoad];
012
//导航栏标题
013
self.navigationItem.title = @"雨松MOMO输入框";
014
015
//导航栏按钮
016
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
017
initWithTitle: @"发送"
018
style: UIBarButtonItemStyleDone
019
target: self
020
action: @selector(sendInfo)] autorelease];
021
022
//输入框显示区域
023
_textEditor = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
024
//设置它的代理
025
_textEditor.delegate = self;
026
_textEditor.autoresizingMask = UIViewAutoresizingFlexibleWidth;
027
_textEditor.keyboardType = UIKeyboardTypeDefault;
028
_textEditor.font = [UIFont systemFontOfSize:20];
029
_textEditor.text = @"请输入内容";
030
031
//默认软键盘是在触摸区域后才会打开
032
//这里表示进入当前ViewController直接打开软键盘
033
[_textEditor becomeFirstResponder];
034
-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: