Ios 此代码是否遵循标准Objective-C和MVC约定?

Ios 此代码是否遵循标准Objective-C和MVC约定?,ios,objective-c,model-view-controller,conventions,Ios,Objective C,Model View Controller,Conventions,我已经用Objective-C编写了一个基本的应用程序,它显示了一个用户联系人的图片。问题是,没有划分,我觉得我违反了某些标准 一切都是通过一个主ViewController处理的,它主要在用户点击按钮(通过IB的出口)后开始工作 // //ViewController.m //未来4 // //由Rooz Mahdavian于2013年5月31日创建。 //版权所有(c)2013 Rooz Mahdavian。版权所有。 // #导入“ViewController.h” #进口 #进口 #进口

我已经用Objective-C编写了一个基本的应用程序,它显示了一个用户联系人的图片。问题是,没有划分,我觉得我违反了某些标准

一切都是通过一个主ViewController处理的,它主要在用户点击按钮(通过IB的出口)后开始工作

//
//ViewController.m
//未来4
//
//由Rooz Mahdavian于2013年5月31日创建。
//版权所有(c)2013 Rooz Mahdavian。版权所有。
//
#导入“ViewController.h”
#进口
#进口
#进口
@界面视图控制器()
@结束
@实现视图控制器
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
UITapGestureRecognizer*singleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(userAllowedForAccess)];
singleTap.numberOfTapsRequired=1;
singleTap.numberOfTouchesRequired=1;
[[self.view view withtag:300]addgestureRecognitor:singleTap];
[[self.view view withtag:300]setUserInteractionEnabled:YES];
CGRect TEMPBUTON=[self.view viewWithTag:300].frame;
tempButton.origin.y=self.view.frame.size.height/2-56;
[self.view view with tag:300].frame=tempButton;
[UIView beginAnimations:nil上下文:nil];
[UIView setAnimationDuration:.4];
[UIView setAnimationDelay:0];
[UIView设置动画曲线:UIViewAnimationCurveEaseOut];
CGRect tempButton2=[self.view viewWithTag:300].frame;
tempButton2.原点y+=90;
[self.view view with tag:300].frame=tempButton2;
[self.view view with tag:100].alpha=1;
[UIView委员会];
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
-(iAction)用户允许访问{
NSLog(@“用户已验证联系人”);
UIView*头文件=[[UIView alloc]initWithFrame:CGRectMake(0,0320,55)];
header.backgroundColor=[UIColor colorWithRed:34/255.0绿色:34/255.0蓝色:34/255.0 alpha:1];
[header.layer setShadowColor:[UIColor colorWithRed:14/255.0绿:14/255.0蓝:14/255.0 alpha:.5].CGColor];
[header.layer setShadowOpacity:0];
[header.layer setShadowRadius:3.0];
[header.layer setShadowOffset:CGSizeMake(2.0,2.0)];
[self.view addSubview:header];
[self.view将子视图带到前面:[带标签的self.view视图:100];
[UIView beginAnimations:nil上下文:nil];
[UIView setAnimationDuration:.7];
[UIView setAnimationDelay:0];
[UIView设置动画曲线:UIViewAnimationCurveEaseOut];
CGRect tempLogo=[self.view viewWithTag:100].frame;
tempLogo.origin.y=-14;
tempLogo.size.height=tempLogo.size.height/2.5;
tempLogo.size.width=tempLogo.size.width/2.5;
tempLogo.origin.x=160-tempLogo.size.width/2;
[self.view-viewWithTag:100].frame=tempLogo;
CGRect TEMPBUTON=[self.view viewWithTag:300].frame;
tempButton.size.width=tempButton.size.width*2.5;
tempButton.size.height=tempButton.size.height*2.5;
tempButton.origin.x=-((tempButton.size.width/2)-(tempButton.size.width*2.5))/2);
[self.view view with tag:300].frame=tempButton;
[self.view view with tag:300].alpha=0;
[self.view view with tag:200].alpha=0;
[header.layer setShadowOpacity:1];
[UIView委员会];
ABAddressBookRef addressBook=ABAddressBookCreate();
UIScrollView*scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(0,60,self.view.frame.size.width,self.view.frame.size.height)];
__block BOOL accessgrated=否;
如果(ABAddressBookRequestAccessWithCompletion!=NULL){//我们在iOS 6上
dispatch\u semaphore\u t sema=dispatch\u semaphore\u create(0);
ABAddressBookRequestAccessWithCompletion(addressBook,^(已授予bool,CFErrorRef错误){
accessgrated=已授予;
调度信号量信号(sema);
});
调度信号量等待(永远调度时间);
}
CFArrayRef allPeople=abAddressBookCopyArrayFallPeople(addressBook);
CFIndex nppeople=ABAddressBookGetPersonCount(地址簿);
int peopleInARow=0;
int maxPeopleInARow=3;
int positionFromTop=20;
int IMAGE_SIZE=70;
float animationOffset=.5;
float animationOffsetChange=.3;
浮动动画持续时间=.5;
int scaleOffset=40;
int屏幕宽度=320;
int开始位置from左=26;
int positionFromLeft=起始位置FROMLEFT;
int-topOffset=40;
int leftOffset=26;
int numberOfRows=0;
UIView*contactContainer;
UIImage*图像;
卡拉耶*l;
NSString*名称;
NSString*lastName;
NSString*名字;
UIImageView*新建ImageView;
UILabel*标签;
UIView*contactImageContainer;
for(int i=0;i//
//  ViewController.m
//  Future Take 4
//
//  Created by Rooz Mahdavian on 5/31/13.
//  Copyright (c) 2013 Rooz Mahdavian. All rights reserved.
//

#import "ViewController.h"
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
#import <QuartzCore/QuartzCore.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(userAllowedForAccess)];
    singleTap.numberOfTapsRequired = 1;
    singleTap.numberOfTouchesRequired = 1;
    [[self.view viewWithTag:300] addGestureRecognizer:singleTap];
    [[self.view viewWithTag:300] setUserInteractionEnabled:YES];

    CGRect tempButton = [self.view viewWithTag:300].frame;
    tempButton.origin.y = self.view.frame.size.height/2 - 56;
    [self.view viewWithTag:300].frame = tempButton;

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration: .4];
    [UIView setAnimationDelay: 0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

    CGRect tempButton2 = [self.view viewWithTag:300].frame;
    tempButton2.origin.y += 90;
    [self.view viewWithTag:300].frame = tempButton2;

    [self.view viewWithTag:100].alpha = 1;

    [UIView commitAnimations];


}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)userAllowedForAccess {
    NSLog(@"User Has Verified Contacts");


    UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0,0, 320, 55)];
    header.backgroundColor = [UIColor colorWithRed:34/255.0 green:34/255.0 blue:34/255.0 alpha:1];

    [header.layer setShadowColor:[UIColor colorWithRed:14/255.0 green:14/255.0 blue:14/255.0 alpha:.5].CGColor];
    [header.layer setShadowOpacity:0];
    [header.layer setShadowRadius:3.0];
    [header.layer setShadowOffset:CGSizeMake(2.0, 2.0)];

    [self.view addSubview:header];
    [self.view bringSubviewToFront:[self.view viewWithTag:100]];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration: .7];
    [UIView setAnimationDelay: 0];


    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

    CGRect tempLogo = [self.view viewWithTag:100].frame;
    tempLogo.origin.y = -14;
    tempLogo.size.height = tempLogo.size.height/2.5;
    tempLogo.size.width = tempLogo.size.width/2.5;
    tempLogo.origin.x = 160 - tempLogo.size.width/2;
    [self.view viewWithTag:100].frame = tempLogo;

    CGRect tempButton = [self.view viewWithTag:300].frame;
    tempButton.size.width = tempButton.size.width * 2.5;
    tempButton.size.height = tempButton.size.height * 2.5;
    tempButton.origin.x = -((tempButton.size.width/2)-((tempButton.size.width * 2.5))/2);

    [self.view viewWithTag:300].frame = tempButton;
    [self.view viewWithTag:300].alpha = 0;


    [self.view viewWithTag:200].alpha = 0;
    [header.layer setShadowOpacity:1];

    [UIView commitAnimations];





    ABAddressBookRef addressBook = ABAddressBookCreate();
    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 60, self.view.frame.size.width, self.view.frame.size.height)];




    __block BOOL accessGranted = NO;
    if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6
        dispatch_semaphore_t sema = dispatch_semaphore_create(0);
        ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
            accessGranted = granted;
            dispatch_semaphore_signal(sema);
        });
        dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
    }


    CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
    CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );


    int peopleInARow = 0;
    int maxPeopleInARow = 3;
    int positionFromTop = 20;
    int IMAGE_SIZE = 70;
    float animationOffset = .5;
    float animationOffsetChange = .3;
    float animationDuration = .5;
    int scaleOffset = 40;
    int screenWidth = 320;
    int startingPositionFromLeft = 26;
    int positionFromLeft = startingPositionFromLeft;
    int topOffset = 40;
    int leftOffset = 26;
    int numberOfRows = 0;


    UIView *contactContainer;
    UIImage* image;
    CALayer * l;
    NSString* name;
    NSString* lastName;
    NSString* firstName;
    UIImageView *newimageview;
    UILabel *label;
    UIView *contactImageContainer;



    for ( int i = 0; i < nPeople; i++ )
    {
        ABRecordRef person = CFArrayGetValueAtIndex( allPeople, i );
        firstName = (__bridge_transfer NSString*)ABRecordCopyValue(person,
                                               kABPersonFirstNameProperty);
        lastName = (__bridge_transfer NSString*)ABRecordCopyValue(person,
                                               kABPersonLastNameProperty);
         name = [NSString stringWithFormat:@"%@ %@", firstName, lastName];





        if(ABPersonHasImageData(person)){
            //NSLog(@"%@", name);
            image = [UIImage imageWithData:(__bridge NSData *)ABPersonCopyImageData(person)];

            //NSLog(@"Position %i", positionFromLeft);
            newimageview = [[UIImageView alloc] initWithFrame:CGRectMake(-scaleOffset/2, -scaleOffset/2, IMAGE_SIZE+scaleOffset, IMAGE_SIZE+scaleOffset)];
            newimageview.contentMode = UIViewContentModeScaleAspectFit;




            [newimageview setImage: image];


            contactContainer = [[UIView alloc] initWithFrame:CGRectMake(positionFromLeft, positionFromTop + 20, IMAGE_SIZE, 200)];
            contactImageContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, IMAGE_SIZE, IMAGE_SIZE)];
            contactImageContainer.clipsToBounds = YES;

            l = [contactImageContainer layer];
            [l setMasksToBounds:YES];
            [l setCornerRadius:IMAGE_SIZE/2];

            // You can even add a border
            [l setBorderWidth:0.0];
            [l setBorderColor:[[UIColor colorWithRed:234.0/255.0 green:234.0/255.0 blue:234.0/255.0 alpha:.6] CGColor]];


            [contactImageContainer addSubview:newimageview];







            [contactContainer addSubview:contactImageContainer];

            label =  [[UILabel alloc] initWithFrame: CGRectMake(0, IMAGE_SIZE + 10, IMAGE_SIZE, 20)];
            label.text = firstName;
            label.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0];
            label.textColor = [UIColor whiteColor];
            [label setTextAlignment:NSTextAlignmentCenter];
            [label setFont:[UIFont fontWithName:@"Arial-BoldMT" size:14]];
            [contactContainer addSubview:label];


            contactContainer.alpha = 0;






            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:animationDuration];
            [UIView setAnimationDelay:animationOffset];
            animationOffset+= animationOffsetChange;
            [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

            contactContainer.alpha = 1;
            CGRect temp = contactContainer.frame;
            temp.origin.y = positionFromTop;
            contactContainer.frame = temp;

            [UIView commitAnimations];

            if(peopleInARow >= 2){
                positionFromTop += IMAGE_SIZE + topOffset;
                peopleInARow = 0;
                positionFromLeft = startingPositionFromLeft;
                numberOfRows++;

            } else {
                peopleInARow += 1;
                positionFromLeft += IMAGE_SIZE + leftOffset;
            }



            [scroll addSubview:contactContainer];
            [scroll bringSubviewToFront:contactContainer];


        }

    }

    NSLog(@"%i", numberOfRows);

    scroll.contentSize = CGSizeMake(screenWidth, 150 * numberOfRows);
    scroll.pagingEnabled = NO;

    [self.view addSubview:scroll];
    [self.view bringSubviewToFront:scroll];


}

- (IBAction)userDeniedAccess:(id)sender {
    NSLog(@"Denied");
}

@end
- (IBAction)userAllowedForAccess
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0,0, 320, 55)];
header.backgroundColor = [UIColor colorWithRed:34/255.0 green:34/255.0 blue:34/255.0 alpha:1];

[header.layer setShadowColor:[UIColor colorWithRed:14/255.0 green:14/255.0 blue:14/255.0 alpha:.5].CGColor];
[header.layer setShadowOpacity:0];
[header.layer setShadowRadius:3.0];
[header.layer setShadowOffset:CGSizeMake(2.0, 2.0)];

[self.view addSubview:header];
[self.view bringSubviewToFront:[self.view viewWithTag:100]];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: .7];
[UIView setAnimationDelay: 0];


[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];