“不要辜负大家”
作者: CouldHll
UIImageView frame设置顺序问题
问题描述:
今天做AD ipad版展示功能点,背景不显示。
问题分析:
检查代码,其他都没什么问题。发现设置frame在设置image之前。
代码如下:
UIImage *backgroundImage=[UIImage imageNamed:BACKGROUND_FILE_NAME];
_backgroundImageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height)];
_backgroundImageView.image=backgroundImage;
问题解决:
把设置frame代码放置在设置frame之后,一切安逸了。
代码如下:
_backgroundImageView=[[UIImageView alloc] init];
UIImage *backgroundImage=[UIImage imageNamed:BACKGROUND_FILE_NAME];
_backgroundImageView.image=backgroundImage;
_backgroundImageView.frame=CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height);
UIButton click不触发问题
问题描述:
今天做AD的ipad版展示功能点,为UIButton加入点击事件后,没有调用效果。
问题分析:
代码如下:
[button addTarget:self action:@selector(groupClicked:) forControlEvents:UIControlEventTouchUpInside];
- (void)objectClicked:(id)vSender
{
}
objectClicked方法没有被调用。查了下,addSubView等都没问题。突然想到父类是UIView,frame没有设定过。
问题解决:
设定frame:self.frame=CGRectMake(0,0,768,961);
一切安逸了。
Resolution for iOS
type resolution dpi
iphone3 320*480 163
iphone4 960*640 326
ipad 1024*768 132
不同iOS SDK对事件调用支持不同
问题描述:
今天做AD杂志(iPad)LEGO功能点,需要在UIScrollView中让UIView移动。加了正确代码,结果却不好。
结果是这样的:点击不移动,运行touchesBegan和touchesEnded,一切正常。但是点下移动释放,touchesBegan会100%运行,然后三两个touchesMoved,move效果也跟不上,touchesEnded也没有触发。
在UIView用了如下代码实现:
#pragma mark --
#pragma mark touch
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesBegan");
UITouch *touch = [touches anyObject];
UIScrollView *parentView = (UIScrollView *)[[[touch view] superview]superview];
parentView.scrollEnabled=NO;
// Calculate and store offset, and pop view into front if needed
CGPoint pt = [[touches anyObject] locationInView:self];
startLocation = pt;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesMoved");
// Calculate offset
CGPoint pt = [[touches anyObject] locationInView:self];
float dx = pt.x - startLocation.x;
float dy = pt.y - startLocation.y;
CGPoint newcenter = CGPointMake(self.center.x + dx, self.center.y + dy);
// Bound movement into parent bounds
float halfx = CGRectGetMidX(self.bounds);
newcenter.x = MAX(halfx, newcenter.x);
newcenter.x = MIN(self.superview.bounds.size.width - halfx, newcenter.x);
float halfy = CGRectGetMidY(self.bounds);
newcenter.y = MAX(halfy, newcenter.y);
newcenter.y = MIN(self.superview.bounds.size.height - halfy, newcenter.y);
// Set new location
self.center = newcenter;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesEnded");
UITouch *touch = [touches anyObject];
UIScrollView *parentView = (UIScrollView *)[[[touch view] superview]superview];
parentView.scrollEnabled=YES;
}
问题分析:
最后一段一段检查,应该是parentView.scrollEnabled=NO;这句有问题。
可能是iOS的一个Bug。
问题解决:
在另一台Mac上做了一个Demo,一切OK。细细检查,唯一不同就是SDK版本不一样。出问题的那台是4.1,而做Demo一切OK的那台是4.2.1。把出问题的代码copy给4.2.1,一切安逸了。
Model
最新迷上二战,买了个虎王模型。
以下是一些模型网站:
我爱模型:http://bbs.5imx.com/bbs/
模型中国:http://bbs.mx3g.com/
模型网:http://www.moxing.net/
AeroFly(Mac下唯一模拟飞行器):http://www.aerofly.com/index.html
Resource of Kinect
Kinect for Windows SDK:http://research.microsoft.com/en-us/um/redmond/projects/kinectsdk/
中国Kinect论坛:http://www.cnkinect.com/
OpenKinect:http://openkinect.org/wiki/Main_Page
OpenNI:http://www.openni.org/
CL NUI Platform:http://codelaboratories.com/nui/
KinectHacks:http://kinecthacks.net/
Nokia6300 for Mac
Installation of the Nokia 6300 iSync-plugin
- Download the Nokia 6300 iSync plugin v. 1.1
- Extract the nokia6300phoneplugin.zip (Your browser might do it for you)
- Quit iSync if its running
- Move the extracted file (Nokia6300.phoneplugin) to ~/Library/PhonePlugins If that folder isn’t there, just create it.
- Start iSync and sync away
不同iOS SDK对缺少文件后缀名图片的调用支持不同
问题描述:
今天做AD杂志(iPad)特色点功能,一段相同代码转移到另一台机器,执行结果却不一样。
问题分析:
代码、项目检查后完全一样,执行效果却不同,也没有报错。
因为结果是Button图片没有显示,所以一步一步检查,搜索到UIImage在转移后没有图片信息,相关代码如下:
#define PHOTO_NAME @"point"
[UIImage imageNamed:PHOTO_NAME];
以上代码实现了读入项目中point.png图片文件。
问题解决:
图片后缀没有给全,改为:
#define PHOTO_NAME @"point.png"
图片出现了,问题解决了。
事后分析,估计是不同SDK对代码的支持不同。所以养成编程好习惯能省许多事情和时间。
PS:
转移前SDK:4.2.1
转移后SDK:4.1
Xcode设置代码提示的左花括号换行单独成行
Xcode代码提示生成源代码程序块默认格式如下,注意左花括号的位置:
if ( condition ) {
do ...
}
因为以前的使用习惯,我想让自动生成的左右花括号都单独成行,变成下面的样子:
if ( condition )
{
do ...
}
在Terminal里面,运行下面命令,然后重启Xcode:
defaults write com.apple.Xcode XCCodeSenseFormattingOptions -dict BlockSeparator "\n"
这个命令修改了~/Library/Preferences/com.apple.Xcode.plist,这是Xcode的配置文件