我想将按钮放在具有动态文本的各个位置(不在导航栏中).我希望它们看起来类似于黑色导航栏按钮项目(灰色和黑色渐变).
我将如何创建这些?它们需要基于按钮文本的动态宽度.我知道我可以创建png文件并拉伸它们,但是有更好的方法吗?
根据Apple的MPMoviePlayerController doc:
MPMoviePlayerPlaybackDidFinishNotification - 如果电影播放器以全屏模式显示并且用户点击完成按钮,则不会发送此通知.
在我看来,这是错误的.使用下面的代码,当我点击完成按钮时,会调用playerPlaybackDidFinish.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.player];
- (void) playerPlaybackDidFinish:(NSNotification*)notification
{
NSLog(@"WHY?");
self.player.fullscreen = NO;
}
Run Code Online (Sandbox Code Playgroud)
我需要区分用户点击完成按钮和电影完成整个播放.当电影结束时,playerPlaybackDidFinish会被调用,但就像我说的那样,当你点击Done时它也会被调用.
在界面中我有这个:
Animal* myPet;
Run Code Online (Sandbox Code Playgroud)
在运行时我可能希望myPet是一只猫或一只狗,它们是Animal的子类:
id newPet;
if(someCondition) {
newPet = [[Cat alloc] initWithNibName:@"Cat" bundle:nil];
} else {
newPet = [[Dog alloc] initWithNibName:@"Dog" bundle:nil];
}
self.myPet = newPet;
Run Code Online (Sandbox Code Playgroud)
显然这是不正确的,但我希望它足以显示我正在尝试做的事情.这样做的最佳做法是什么?
看吧:
//UIImageView* stretchTest = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
//[self addSubview:stretchTest];
UIButton *stretchTest = [UIButton buttonWithType:UIButtonTypeCustom];
[stretchTest setFrame:CGRectMake(0, 0, 400, 100)];
[stretchTest setBackgroundImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
[self addSubview:stretchTest];
stretchTest.contentStretch = CGRectMake(0.5, 0.5, 0, 0);
stretchTest.contentMode = UIViewContentModeScaleToFill;
CGRect frame = stretchTest.frame;
frame.size.height = 300;
stretchTest.frame = frame;
Run Code Online (Sandbox Code Playgroud)
使用UIImageView(上面已注释),图像适当拉伸 - 圆角保持正确的半径,因为只有图像的中心像素被拉伸.
使用UIButton,图像被错误地拉伸.角半径没有保持,它变得丑陋.
UIImageView和UIButton都是UIView的子类.为什么按钮的调整大小与imageView不同?
我最近更改了一些代码以使用集合而不是向量:
std::set<b2Body *>toDestroy;
//std::vector<b2Body *>toDestroy;
Run Code Online (Sandbox Code Playgroud)
但是现在我不确定如何迭代集合来查找对象.这就是我所拥有的:
std::vector<b2Body *>::iterator pos2;
for(pos2 = toDestroy.begin(); pos2 != toDestroy.end(); ++pos2) {
b2Body *body = *pos2;
if (body->GetUserData() != NULL) {
CCSprite *sprite = (CCSprite *) body->GetUserData();
[self removeChild:sprite cleanup:YES];
}
_world->DestroyBody(body);
}
Run Code Online (Sandbox Code Playgroud)
现在toDestroy是一个集合的等价物是什么?来自Objective-C所以我只是学习C++的最佳实践.
编辑:添加我得到的错误消息:
error: no match for 'operator=' in 'pos2 = toDestroy. std::set<_Key, _Compare, _Alloc>::begin [with _Key = b2Body*, _Compare = std::less<b2Body*>, _Alloc = std::allocator<b2Body*>]()'
Run Code Online (Sandbox Code Playgroud) 在从外部源加载数据之前,我不想显示我的表视图单元格.我想在加载数据时在表格背景上显示活动指示符.我可以通过将它作为子视图添加到tableView来显示指示器,但我无法弄清楚如何隐藏行直到它们准备好显示.
这都是在UITableViewController中处理的.该表以弹出框形式显示.
这让我很困惑.我希望在方向更改时更改UIScrollView的框架:
if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight){
self.myScrollView.frame = CGRectMake(40, 40, 984, 200);
for (UIView* view in [self.myScrollView subviews]){
NSLog(@"subview x: %f", view.frame.origin.x);
}
}
else{
self.myScrollView.frame = CGRectMake(40, 40, 728, 200);
for (UIView* view in [self.myScrollView subviews]){
NSLog(@"subview x portrait: %f", view.frame.origin.x);
}
}
Run Code Online (Sandbox Code Playgroud)
结果如下.请注意,子视图向左移动了156个像素,即使我所做的只是更改父滚动视图的宽度(纵向模式下小256像素):
subview x: 0.000000
subview x: 128.000000
subview x: 256.000000
subview x: 384.000000
subview x portrait: -156.000000
subview x portrait: -28.000000
subview x portrait: 100.000000
subview x portrait: 228.000000
Run Code Online (Sandbox Code Playgroud)
为什么??我该如何防止这种情况?
任何人都可以解释为什么在使用loadView时不会调用viewDidLoad?我的理解是viewDidLoad应该仍然被调用.
- (void)loadView
{
CGRect currentFrame = [[UIScreen mainScreen] applicationFrame];
UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(currentFrame.origin.x, currentFrame.origin.y, currentFrame.size.width, currentFrame.size.height)];
myView.backgroundColor = [UIColor redColor];
self.view = myView;
[myView release];
[super loadView];
}
- (void)viewDidLoad {
//this never happens
NSLog(@"VIEW DID LOAD!");
[super viewDidLoad];
}
Run Code Online (Sandbox Code Playgroud) 我有一个仅限肖像模式的应用程序,但是当用户播放视频时,我希望它以全屏横向模式播放(视频播放器在纵向模式下看起来不太好).我这样玩:
[self.view addSubview:myMoviePlayer.view];
[self.myMoviePlayer setFullscreen:YES animated:YES];
[self.myMoviePlayer play];
Run Code Online (Sandbox Code Playgroud)
实现这一目标的最佳方法是什么?
我的tableView包含5-10个单元格,每个单元格包含一个图像滚动视图.问题是,当一个单元格离开屏幕时,它将删除所有图像,然后在单元格返回屏幕时重新加载它们.我知道这是出于性能原因,但在这种情况下,它看起来很糟糕.有没有办法防止细胞在离开屏幕时卸载?
iphone ×6
ipad ×4
objective-c ×3
ios ×2
uitableview ×2
button ×1
c++ ×1
class ×1
iterator ×1
loadview ×1
positioning ×1
runtime ×1
set ×1
std ×1
uibutton ×1
uiimageview ×1
uiscrollview ×1
uiview ×1
video ×1
viewdidload ×1
xcode ×1