设置标签 ‘UIView’

IMIUI update

Just want you know I’m keeping on my fav baby “IMIKit”.

IMIUIKitshot.png

So, recently I focused on the UI part of IMIKit , I have the IMIUICheckBox, IMIUIPieView, IMIUILoadingView & IMIUISwitch

[2010-5-21: REVISION 672]

[NEW] add “IMIUIRandomColor” to get a random UIColor

[NEW] add yesImage & noImage method into UIImage for merged stat image

[NEW] add IMIUIPieView to draw a pie chart

[CHANGED] instead UIImageView with “draw” in IMIUILoadingView to lay down the memory usage (a little bit)

IMIUIPieView:
give as many values and colors to show whatever theme

IMIUILoadingView:
has 3 styles: SingleCell, StepCell & RandomCell

IMIUISwitch:
The native UISwitch is so “huge”, use mine to instead it

The next aim maybe IMIUIContextMenu


半透明状态栏与导航条的错位

iPhone的状态栏可以设置成半透明, 这是众所周知的, 用UINavigationController,在页面切换时, 如果你的子viewController的view是全屏的(480*320) 就会出现错位, 表现是所以的子view会向下偏移了 20像素 (就是状态栏的高度).

我搜索了好长时间也没有找到答案, 于是自己去看官方文档, 结果发现了这个方法, 这是UIViewController的一个属性.

wantsFullScreenLayout

看字面意思就很好理解(苹果的方法名都很好理解, 还是带时态和语法的 很人性化), 就是”我要全屏布局” 这样错位的问题就解决了

把UIView覆盖到状态栏上的方法

Reeder

View In iTunes

最近iPhone上的一个新闻阅读软件 Reeder 更新了, 非常好用, 稳定,而且速度飞快. 用了之后 我立马就把原来的 Byline 删除了.

这个软件征服我这个吹毛求疵的人的一个地方, 其实在于一个小细节, 有了这个细节, 我觉得, 这软件值了!

这个细节就是系统状态栏图标, 从来没有一个程序在状态栏上做文章, Reeder 做到了, 新闻的刷新, 图片加载, 在系统状态栏上显示, 显得非常的苹果味道, 如图:

IMG_0177.png

当然, 本文是讨论技术, 不是软件评测.

国外好多论坛上在问这个问题,但答案都是需要Private API之类的,无法上Store的方法. 但是Reeder怎么可以? 我也得可以才行 :) ,经过一段时间的琢磨, 我知道了这个实现方法, 分享给大家.

方法的原理就是, 生成一个新的UIWindow, 把这个Window放在状态栏之上! 其实这个效果早在2.0的时候就能实现, 只是我们这些不求甚解, 学习不扎实的人没有注意到罢了.

那具体怎么做, 我先卖个关子, 大家自己根据这思路研究一下, 其实, 很简单, 很简单, 我几天后公布答案 :) 不要抢答噢 嘎嘎~~~

——————————–

公布答案:

首先 继承 UIWindow, init的方法: 关键的语句 self.windowLevel=UIWindowLevelAlert;

- (id) init

{

CGRect f=[[UIScreen mainScreen] bounds];

CGRect s=[[UIApplication sharedApplication] statusBarFrame];

self = [super initWithFrame:CGRectMake(0, 0, f.size.width, s.size.height)];

if (self != nil) {

self.windowLevel=UIWindowLevelAlert;

self.backgroundColor=[UIColor clearColor];

[self makeKeyAndVisible];

}

return self;

}

现在 在这个window添加view 就会覆盖到状态栏上了, 你猜对了么??

Cocos2D for iPhone 的触摸事件

除了 Layer 可以接受触摸事件, 在Cocos2D 0.8以后加入一个新的特性,从而让所有的对象都可以接受触摸事件. 发现大家都不怎么用这个方法,这儿简单介绍一下.

首先添加事件接收者:

[[TouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:1 swallowsTouches:NO];

//self为接收者, 优先级参数从0开始 数字越小优先级越高,就会越先接收到事件, 最后一个参数表示是否阻止此次事件冒泡

然后实现3个方法:

#pragma mark TouchDispatcherDelegate

- (BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{

//你的代码

return YES; //这儿如果返回NO 此次触摸将被忽略

}

- (void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event

{

//你的代码

}

- (void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event{

//你的代码

}

这样,就可以像处理UIView里的事件一样去处理coco2d了.

Enjoy ur coding :)

Edit: 别忘了删除监听者, 要不然……

[[TouchDispatcher sharedDispatcher] removeDelegate:self];

防止播放视频前的黑屏

Hi
In order to make a seamlessly looping video using MediaPlayer (which annoyingly fades in and out of movies) I used the trick of setting the MP’s background to clearColor and loading a JPG of the first frame into the Main Window, so the movie then fades to transparent revealing the still and hopefully no-one’s the wiser.
Being a complete n00b I just wanted to check i was doing this the right way, because in the Simulator it runs fine, on the phone it runs fine once then each loop after that jumps to black before playing.

In my AppDelegate.m file I have


- (void)applicationDidFinishLaunching:(UIApplication *)application {

UIView *mview= [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
UIImageView *img=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"background.jpg"]];
img.frame=CGRectMake(0, 0, img.frame.size.width, img.frame.size.height);
[mview addSubview:img];
[img release];
[window addSubview:viewController.view];
[window addSubview:mview];
[window makeKeyAndVisible];
[window sendSubviewToBack:viewController.view];
[mview release];
}

which loads the background image (I think!). The looping video is accomplished in MainView.m with:


-(void)awakeFromNib {

NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"MyVid" ofType:@"m4v"];

NSURL *movieURL;

if (moviePath)
{
movieURL = [NSURL fileURLWithPath:moviePath];
}

if (movieURL != nil) {
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];

moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
moviePlayer.movieControlMode = MPMovieControlModeHidden;
moviePlayer.backgroundColor = [UIColor clearColor];

[moviePlayer play];
}

}

-(void)moviePlayBackDidFinish: (NSNotification*)notification
{
moviePlayer = [notification object];
[moviePlayer play];
}

The movie plays and sends a notification when it’s finished so it’s played again.
Any advice on how to do this more efficiently and prevent black flashes between playbacks would be greatly appreciated!

Cheers
Lucas

Different between viewDidDisappear & viewWillDisappear

Recently I have a proj using UIView animation, the animation delegated to a view’s delegate. View’s delegate is a view controller in list of nav Controllers.
Clear, then when I pop out the controller , all of the views and the controller should be released, BUT the animation CAN NOT stop, so a bad_access throwd out when animation finish, bcz the delegate had been released then.
After some digging, viewDidDisappear & viewWillDisappear come to the ground, viewDidDisappear would be right! drop lines if you have clearly knowladged.

回到顶部

关于我:

  • iPhone 开发者. 自由职业者.
  • 苹果忠实用户. 完美主义者.
  • Email/iChat/MSN/GTalk: i@imi.im
  • Twitter/Sina: @TraWor
  •  

    Switch to our mobile site