码迷,mamicode.com
首页 > 其他好文 > 详细

照片墙

时间:2017-10-07 17:38:00      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:desc   pass   from   copy   returns   atomic   obj   col   phi   

  1 //
  2 //  AppDelegate.m
  3 //  PicWall
  4 //
  5 //  Created by wky on 07/10/2017.
  6 //  Copyright ? 2017 vector. All rights reserved.
  7 //
  8 
  9 #import "AppDelegate.h"
 10 #import "VCRoot.h"
 11 
 12 @interface AppDelegate ()
 13 
 14 @end
 15 
 16 @implementation AppDelegate
 17 
 18 
 19 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 20     // Override point for customization after application launch.
 21     
 22     self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
 23     
 24     VCRoot* vcRoot = [[VCRoot alloc]init];
 25     
 26     UINavigationController* nav = [[UINavigationController alloc]initWithRootViewController:vcRoot];
 27     
 28     self.window.rootViewController = nav;
 29     
 30     [self.window makeKeyAndVisible];
 31     
 32     
 33     
 34     
 35     return YES;
 36 }
 37 
 38 
 39 - (void)applicationWillResignActive:(UIApplication *)application {
 40     // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
 41     // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
 42 }
 43 
 44 
 45 - (void)applicationDidEnterBackground:(UIApplication *)application {
 46     // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
 47     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
 48 }
 49 
 50 
 51 - (void)applicationWillEnterForeground:(UIApplication *)application {
 52     // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
 53 }
 54 
 55 
 56 - (void)applicationDidBecomeActive:(UIApplication *)application {
 57     // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
 58 }
 59 
 60 
 61 - (void)applicationWillTerminate:(UIApplication *)application {
 62     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
 63     // Saves changes in the application‘s managed object context before the application terminates.
 64     [self saveContext];
 65 }
 66 
 67 
 68 #pragma mark - Core Data stack
 69 
 70 @synthesize persistentContainer = _persistentContainer;
 71 
 72 - (NSPersistentContainer *)persistentContainer {
 73     // The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it.
 74     @synchronized (self) {
 75         if (_persistentContainer == nil) {
 76             _persistentContainer = [[NSPersistentContainer alloc] initWithName:@"PicWall"];
 77             [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) {
 78                 if (error != nil) {
 79                     // Replace this implementation with code to handle the error appropriately.
 80                     // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
 81                     
 82                     /*
 83                      Typical reasons for an error here include:
 84                      * The parent directory does not exist, cannot be created, or disallows writing.
 85                      * The persistent store is not accessible, due to permissions or data protection when the device is locked.
 86                      * The device is out of space.
 87                      * The store could not be migrated to the current model version.
 88                      Check the error message to determine what the actual problem was.
 89                     */
 90                     NSLog(@"Unresolved error %@, %@", error, error.userInfo);
 91                     abort();
 92                 }
 93             }];
 94         }
 95     }
 96     
 97     return _persistentContainer;
 98 }
 99 
100 #pragma mark - Core Data Saving support
101 
102 - (void)saveContext {
103     NSManagedObjectContext *context = self.persistentContainer.viewContext;
104     NSError *error = nil;
105     if ([context hasChanges] && ![context save:&error]) {
106         // Replace this implementation with code to handle the error appropriately.
107         // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
108         NSLog(@"Unresolved error %@, %@", error, error.userInfo);
109         abort();
110     }
111 }
112 
113 @end
  1 //
  2 //  VCRoot.m
  3 //  PicWall
  4 //
  5 //  Created by wky on 07/10/2017.
  6 //  Copyright ? 2017 vector. All rights reserved.
  7 //
  8 
  9 #import "VCRoot.h"
 10 #import "VCImageShow.h"
 11 
 12 @interface VCRoot ()
 13 
 14 @end
 15 
 16 @implementation VCRoot
 17 
 18 - (void)viewDidLoad {
 19     [super viewDidLoad];
 20     // Do any additional setup after loading the view.
 21     
 22     self.title = @"照片墙";
 23     
 24     self.view.backgroundColor = [UIColor whiteColor];
 25     
 26     self.navigationController.navigationBar.translucent = NO;
 27     
 28     UIScrollView* sv = [[UIScrollView alloc]init];
 29     
 30     //设置位置大小
 31     //sv.frame = CGRectMake(10,10,350, 600);
 32     sv.frame = CGRectMake(10,10,300, 480);
 33 
 34     sv.showsVerticalScrollIndicator = NO;
 35     
 36     //设置画布大小
 37     sv.contentSize = CGSizeMake(300,150*4);
 38     
 39     sv.userInteractionEnabled = YES;
 40     
 41     for(int i= 0;i<12;i++)
 42     {
 43         NSString* str = [NSString stringWithFormat:@"image/%d",i+1];
 44         
 45         NSLog(@"%@", str);
 46         
 47         UIImage* img =  [UIImage imageNamed:str];
 48         
 49         UIImageView* imgView = [[UIImageView alloc]initWithImage:img];
 50         
 51         imgView.frame = CGRectMake((i%3)*100+3, (i/3)*140+10, 90, 130);
 52         
 53         imgView.userInteractionEnabled = YES;
 54         
 55         imgView.tag = 101 +i;
 56         
 57         [sv addSubview:imgView];
 58         
 59         UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pressTap:)];
 60         
 61         [imgView addGestureRecognizer:tap];
 62         
 63         tap.numberOfTapsRequired = 1;
 64         
 65         tap.numberOfTouchesRequired = 1;
 66         
 67         //tap.userInteractionEnabled = YES;
 68         
 69         
 70         
 71     }
 72     [self.view addSubview:sv];
 73     
 74     
 75     
 76 }
 77 
 78 //方法二,传tag
 79 -(void) pressTap:(UIGestureRecognizer*) tap
 80 {
 81     //获取当前手势所点击的图片视图
 82     UIImageView* imageView =(UIImageView*) tap.view;
 83     
 84     VCImageShow* imageShow = [[VCImageShow alloc]init];
 85     
 86     //imageShow.image = imageView.image;
 87     
 88     imageShow.imgTag = imageView.tag;
 89     
 90     
 91     
 92     [self.navigationController pushViewController:imageShow animated:YES];
 93     
 94 }
 95 
 96 
 97 
 98 
 99 
100 
101 
102 /*方法一:传图片
103 -(void) pressTap:(UIGestureRecognizer*) tap
104 {
105    //获取当前手势所点击的图片视图
106     UIImageView* imageView =(UIImageView*) tap.view;
107     
108     VCImageShow* imageShow = [[VCImageShow alloc]init];
109     
110     imageShow.image = imageView.image;
111     
112     [self.navigationController pushViewController:imageShow animated:YES];
113     
114 }
115 */
116 
117 
118 
119 - (void)didReceiveMemoryWarning {
120     [super didReceiveMemoryWarning];
121     // Dispose of any resources that can be recreated.
122 }
123 
124 /*
125 #pragma mark - Navigation
126 
127 // In a storyboard-based application, you will often want to do a little preparation before navigation
128 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
129     // Get the new view controller using [segue destinationViewController].
130     // Pass the selected object to the new view controller.
131 }
132 */
133 
134 @end
 1 //
 2 //  VCImageShow.m
 3 //  PicWall
 4 //
 5 //  Created by wky on 07/10/2017.
 6 //  Copyright ? 2017 vector. All rights reserved.
 7 //
 8 
 9 #import "VCImageShow.h"
10 
11 @interface VCImageShow ()
12 
13 @end
14 
15 @implementation VCImageShow
16 
17 - (void)viewDidLoad {
18     [super viewDidLoad];
19     // Do any additional setup after loading the view.
20     
21     self.title = @"图片展示";
22     
23     UIImageView* iView = [[UIImageView alloc]init];
24     
25     iView.frame = CGRectMake(0, 0, 350, 600);
26     
27     
28     /*方法一:传图片
29     iView.image = self.image;
30     */
31 
32     //方法二,传tag
33     UIImage* img = [UIImage imageNamed:[NSString stringWithFormat:@"image/%lu",_imgTag-100]];
34     iView.image = img;
35     
36     [self.view addSubview:iView];
37     
38     
39 }
40 
41 - (void)didReceiveMemoryWarning {
42     [super didReceiveMemoryWarning];
43     // Dispose of any resources that can be recreated.
44 }
45 
46 /*
47 #pragma mark - Navigation
48 
49 // In a storyboard-based application, you will often want to do a little preparation before navigation
50 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
51     // Get the new view controller using [segue destinationViewController].
52     // Pass the selected object to the new view controller.
53 }
54 */
55 
56 @end
 1 //
 2 //  VCImageShow.h
 3 //  PicWall
 4 //
 5 //  Created by wky on 07/10/2017.
 6 //  Copyright ? 2017 vector. All rights reserved.
 7 //
 8 
 9 #import <UIKit/UIKit.h>
10 
11 @interface VCImageShow : UIViewController
12 
13 @property(nonatomic,assign) NSUInteger imgTag;
14 @property(nonatomic,retain) UIImage* image;
15 
16 @end

 

照片墙

标签:desc   pass   from   copy   returns   atomic   obj   col   phi   

原文地址:http://www.cnblogs.com/vector11248/p/7635084.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!