Ios开发知识点小结
来源:互联网 发布:网络技术支持与维护 编辑:程序博客网 时间:2024/04/29 21:27
关于MVC分层设计:
MVC分层将逻辑和界面控件分开, 控件对应相关的函数来响应操作.
在ios开发中, 最简单最快的就是利用视图控制(.xib)来完成界面,控件等非逻辑处理。
让然,也可以手动分层,全用代码控制。 由于我第一次接触MVC模式开发,开始不太习惯,所以在项目中还是用的老方法,要什么就写什么。
六角跳棋中,底层为棋盘:
chessBoardImg = [UIImageimageNamed:@"紫高亮.jpg"]; // UIImage 设置图片,将贴在底层容器中哦给你无
chessBoardViewImg = [[UIImageViewalloc]initWithImage:chessBoardImg]; //UIImageView 一个视图, 并贴上图片。
[chessBoardViewImgsetFrame:CGRectMake(0, 0, 320, 480)]; //给视图设置显示窗口
[selfinsertSubview:chessBoardViewImgatIndex: 0]; //将图片置于底层
棋盘图片放置在底层。 棋子为button,贴在棋盘上面, 每个棋子都有对应的相应函数:
[redChessBt addTarget:selfaction:@selector(redChessSelect:)forControlEvents:UIControlEventTouchUpInside];
// 放置浮动菜单
CGRect menuRect;
menuRect =CGRectMake(0, 435, 320, 80);
menuView = [[UIViewalloc]initWithFrame:menuRect]; // 增加一个UIView 视图
menuViewImg = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"菜单.png"]];
[menuViewImgsetFrame:CGRectMake(0, 0, 320, 80)];
[menuViewaddSubview:menuViewImg];// 图片填充视图
//初始化重新开始,返回, 帮助,菜单四个按钮。
clearBoard = [[UIButtonalloc]initWithFrame:CGRectMake(115, 45, 90, 35)];
[clearBoardsetImage:restartImgforState:UIControlStateNormal]; //原始图片效果
[clearBoardsetImage:restartImg1forState:UIControlStateHighlighted]; //点击后图片的效果。
[clearBoardaddTarget:selfaction:@selector(restartGame:)forControlEvents:UIControlEventTouchUpInside];
[menuViewaddSubview:clearBoard]; // clearBoard按钮属于menuView 视图
backHome = [[UIButtonalloc]initWithFrame:CGRectMake(12, 45, 60, 35)];
[backHomesetImage:backImgforState:UIControlStateNormal];
[backHomesetImage:backImg1forState:UIControlStateHighlighted];
[backHomeaddTarget:selfaction:@selector(backHome:)forControlEvents:UIControlEventTouchUpInside];
[menuViewaddSubview:backHome];
helpBt = [[UIButtonalloc]initWithFrame:CGRectMake(250, 45, 60, 35)];
[helpBtsetImage:helpImgforState:UIControlStateNormal];
[helpBtsetImage:helpImg1forState:UIControlStateHighlighted];
[helpBtaddTarget:selfaction:@selector(helpView:)forControlEvents:UIControlEventTouchUpInside];
[menuViewaddSubview:helpBt];
Menu = [[UIButtonalloc]initWithFrame:CGRectMake(12, 20, 60, 30)];
[MenuaddTarget:selfaction:@selector(showMenu:)forControlEvents:UIControlEventTouchUpInside];
[menuViewaddSubview:Menu];
[selfaddSubview:menuView];
[selfbringSubviewToFront:menuView];
//从allChess字典中找到关键位置为ap的坐标,并加入allChessTemp临时存放的字典(语法)
CGPoint app =CGPointFromString([allChessobjectForKey:[NSNumbernumberWithInt:ap]]);
[allChessTempsetObject:NSStringFromCGPoint(app)forKey:[NSNumbernumberWithInt:ap]];
// 落子点选择 点击棋盘放大的操作
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if (ifTwoTimeChessBoard ==NO){
CGPoint endTouch;
UITouch *touch = [touchesanyObject];
endTouch = [touchlocationInView:self]; // 只需获取最后的touch坐
chessX = endTouch.x;// 在小棋盘上的x坐标
chessY = endTouch.y;// 在小棋盘上的y坐标
[selfzoomIn]; //棋盘放大
}else{
[selfzoomOut]; //棋盘缩小
}
}
// 棋盘放大
- (void)zoomIn {
int x = (int)(chessX - (Renju_margin1 - Renju_paneSize1/2))/Renju_paneSize1;
int y = (int)(chessY - (Renju_margin1 - Renju_paneSize1/2))/Renju_paneSize1;
float originX;// 棋盘放大后超出边界的x长度
float originY;// 棋盘放大后超出边界的y长度
int bx =Renju_margin1_b + x*Renju_paneSize1_b;
int by =Renju_margin1_b + y*Renju_paneSize1_b;
// ******** 控制点击边界位置时候, 放大棋盘显示棋盘不应该越界 *************
originX = (float)bx -chessX;
originY = (float)by -chessY;
if (originX <= 0) {
originX = 0;
}
if (originY <= 0) {
originY = 0;
}
if (originX >= 320) {
originX = 320;
}
if (originY >=yDown) {
originY =yDown;
}
if (chessX >=0 &&chessX <= xLeft) {
originX = 0;
}
if (chessX >=xRight && chessX <= 320) {
originX = 320;
}
if (chessY >= 100 &&chessY <= yUp) {
originY = 100;
}
if (chessY >= 340 &&chessY <= yDown) {
originY =yDown;
}
if (chessX > xLeft && chessX <xRight) {
originX = 2*chessX - 160;
}
if (chessY > yUp && chessY <yDown) {
originY = 2*chessY - 360;
}
chessX_out = originX;
chessY_out = originY;
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:0.1];
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];
self.transform = CGAffineTransformMakeScale(2, 2); //Scale 放大2倍
self.frame = CGRectMake(0, 0, self.frame.size.width,self.frame.size.height);
[UIViewcommitAnimations];
ifTwoTimeChessBoard =YES;
[delegatescrollviewZoomIn:chessX_outandY:chessY_out];
}else{
return;
}
}
// 恢复成小棋盘
- (void)zoomOut {
[delegatescrollviewZoomOut];
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:0.3];
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];
self.frame = CGRectMake(-160, -160, self.frame.size.width,self.frame.size.height);
self.transform = CGAffineTransformMakeScale(1, 1);
[UIViewcommitAnimations];
self.frame = CGRectMake(0, 0, self.frame.size.width,self.frame.size.height);
ifTwoTimeChessBoard =NO;
choosePosition =NO;
}
- Ios开发知识点小结
- ios知识点小结
- IOS知识点小结
- iOS部分知识点小结
- iOS-部分知识点小结
- IOS开发,知识点小结,ios开发中常用的宏定义总结
- ios开发知识点汇总
- ios开发知识点
- iOS 开发知识点2
- iOS 开发知识点
- iOS开发零碎知识点
- iOS开发零碎知识点
- iOS开发零碎知识点
- iOS开发零碎知识点
- iOS开发零碎知识点
- iOS开发零碎知识点
- iOS开发零碎知识点
- iOS开发零碎知识点
- C++调用WinRAR压缩解压文件
- 打造自己的mingw系统--谈谈msys 源代码编译(1)
- JSON的遍历方式
- Linux下软件包的解压方式大全
- JS函数
- Ios开发知识点小结
- 单片机如何用普通电池供电?
- asp.net中frameset的使用
- 防止多文档文档重复打开
- 复习struts2之访问或添加属性
- 报错:1130-host ... is not allowed to connect to this MySql server
- .ActionContextCleanUp的作用
- 黑马程序员-c#接口和抽象类的区别(非常经典的解说)
- 字符串拷贝和内存拷贝函数