Jiugongge image browser and jiugongge Browser
# Import "ViewController. h"
# Import "Appfz. h"
@ Interface ViewController ()
@ Property (nonatomic, copy) NSArray * apps; // File Read
@ Property (nonatomic, assign) BOOL B; // determine whether to zoom in or out
@ Property (nonatomic, assign) CGRect cgr; // record the coordinates and sizes of the buttons when they are pressed.
-(NSArray *) apps ;//
@ End
@ Implementation ViewController
// Read data
-(NSArray *) apps
{
If (_ apps = nil ){
NSString * path = [[NSBundle mainBundle] pathForResource: @ "myhous. plist" ofType: nil];
NSArray * arr = [NSArray arrayWithContentsOfFile: path];
NSMutableArray * arrM = [NSMutableArray array];
For (NSDictionary * dic in arr ){
Appfz * app = [Appfz appWithdic: dic];
[ArrM addObject: app];
}
_ Apps = arrM;
}
Return _ apps;
}
-(Void) viewDidLoad {
[Super viewDidLoad];
// Basic data
Int index = 4;
CGFloat appW = 95;
CGFloat appH = 95;
CGFloat apptopY = 30;
CGFloat appjxX = (self. view. frame. size. width-index * appW)/(index + 1 );
CGFloat appjxY = appjxX;
For (int I = 0; I <self. apps. count; I ++ ){
Int X = I/index;
Int Y = I % index;
Appfz * app1 = self. apps [I];
// Add the button cyclically
UIButton * app = [UIButton alloc] init];
App. frame = CGRectMake (appjxX + (appW + appjxX) * Y, apptopY + (appH + appjxY) * X + appjxY, appW, appH );
[App setBackgroundImage: [UIImage imageNamed: app1.icon] forState: UIControlStateNormal];
[App setBackgroundImage: [UIImage imageNamed: app1.icon] forState: UIControlStateHighlighted];
[Self. view addSubview: app];
[App addTarget: self action: @ selector (isbutton :) forControlEvents: UIControlEventTouchDown];
}
}
// Define the button Method
-(IBAction) isbutton :( UIButton *) app
{
If (self. B = NO ){
// Assign the button size to self. cgr before enlarging
Self. cgr = app. frame;
[Self button: app];
}
Else
{
[Self smallImgClick: app];}
}
// Enlarge the image
-(Void) button :( UIButton *) app
{
[UIView animateWithDuration: 1.0 animations: ^ {
App. frame = CGRectMake (0, 30,414,706 );
}];
[Self. view bringSubviewToFront: app];
// Do not zoom in after amplification
Self. B = YES;
}
// Image Restoration
-(Void) smallImgClick :( UIButton *) app1
{
[UIView animateWithDuration: 1.0 animations: ^ {
App1.frame = self. cgr;
}];
[Self. view bringSubviewToFront: app1];
Self. B = NO;
}
-(Void) didReceiveMemoryWarning {
[Super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@ End