我想创建一个动画.我可以解释这个问题的最佳方法是,如果你能想象画一个圆圈.它从顶部或12点钟开始,顺时针顺时针绘制,直到它在10秒左右的空间内变成一个完整的圆圈.
我得到的壁橱是使用Core Animation绘制一个围绕中心点旋转的点(使用此处的示例代码).但我对如何绘制圆圈感到茫然?任何建议都非常欢迎.
非常感谢 :)
由于大多数信息与Xcode 3相关,因此很难找到这样做的教程.下面的答案可能会对某些人有所帮助.
我从以下网站获取了以下答案的大部分信息:
我有一个视图控制器,通过该loadView方法以编程方式创建其视图.视图的目的是显示数据模型内容.加载视图时,它在状态和导航栏下正确对齐.
但是稍后我会以模态方式呈现另一个视图,以允许用户选择不同的数据模型来填充视图.这会导致loadView再次调用并重新创建新数据模型所需的UI.问题是视图的内容现在出现在状态和导航栏下面!
请注意,我不使用自动布局,因为必须支持iOS4 :(如果我包含extendedLayout修复 - 它确实解决了问题,但只有在模态的消除动画完成后才会产生跳转效果.我的代码如下,谢谢任何帮助.
- (void)loadView {
CGRect frame = CGRectMake(0, 0, [Constants ScreenWidth], [Constants ScreenHeight] - StatusBarHeight - ToolbarHeight);
self.view = [[UIView alloc] initWithFrame:frame];
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
self.view.autoresizesSubviews = YES;
self.view.backgroundColor = [Constants categoriesScreenBackgroundColor];
CGRect scrollFrame = CGRectMake(0, 0, [Constants ScreenWidth], [Constants ScreenHeight] - StatusBarHeight - ToolbarHeight - ToolbarHeight);
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:scrollFrame];
scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleBottomMargin |
UIViewAutoresizingFlexibleTopMargin;
[self.view addSubview:scrollView];
_toolbarViewController = [self createToolbarViewController];
[self.view addSubview:_toolbarViewController.view];
_toolbarViewController.productInfoWorkflowState …Run Code Online (Sandbox Code Playgroud) 我希望使用Xcode的方案来确定运行我的应用程序的服务器.我有一个应用程序从服务器获取其信息.像大多数人一样,我有一个开发服务器,一个登台服务器和一个生产服务器.
我希望为每个Xcode创建一个方案,其中Xcode将注入正确的URL.我是否复制了运行方案并添加了环境变量?这是最好的做事方式,我不特别希望在我的服务器类中使用#ifdef并在每次更改服务器时将其设置为代码.有人能指出我正确的方向吗?
仅供参考:我正在使用Xcode 5.0.2 iOS7 SDK.
[编辑]每个人都提出了一些很好的建议,但我觉得@ redent84的答案最适合我的需要.虽然我发现有趣的是没有人真正建议使用不同的方案.[/编辑]
我有一个小的UIView,显示重复的电影.当用户点击一个按钮时,另一部电影被加载并显示在同一个UIView中.
问题是在删除第一部电影和显示第二部电影之间有半秒钟的"闪光".有没有删除它?
- (void) setUpMovie:(NSString*)title {
NSString *url = [[NSBundle mainBundle] pathForResource:title ofType:@"mp4"];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
[[player view] setFrame:self.movieView.bounds];
[self.movieView addSubview:player.view];
if ([title isEqualToString:@"Bo_idle_02"]) {
[player setRepeatMode:MPMovieRepeatModeOne];
} else {
[player setRepeatMode:MPMovieRepeatModeNone];
}
[player setControlStyle:MPMovieControlStyleNone];
[player play];
}
- (void) startDanceAnimation { [self setUpMovie:@"Bo_dance_02"]; return; }
Run Code Online (Sandbox Code Playgroud) [更新]
按照建议,我更改了所有父视图控制器以支持所有方向.我的app结构如下:AppDelegate> RootViewController> Videos> VideoDetails> MPMoviePlayerViewController.
如果我改变所有这些以支持所有方向,视频将在风景中播放.但支持所有方向并不是我想要的,并导致其他问题.还有其他工作或我可以做的其他事情吗?
谢谢
[/更新]
我有一个基于肖像的iPhone应用程序,它使用MPMoviePlayerViewController的自定义子类显示视频.当用户按下播放时,我创建了这个类的实例,并按模式呈现它,如下所示:
- (IBAction) playPressed:(id)sender {
NSString *filepath = [[NSBundle mainBundle] pathForResource:self.currentVideoModel.videoFileName ofType:@"m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
// MovieViewController is just a simple subclass of MPMoviePlayerViewController
self.moviePlayerController = [[MovieViewController alloc] initWithContentURL:fileURL];
// full screen code.
[self.moviePlayerController.moviePlayer setScalingMode:MPMovieScalingModeFill];
[self.moviePlayerController.moviePlayer setFullscreen:TRUE];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayerController];
[self presentMoviePlayerViewControllerAnimated:self.moviePlayerController];
}
Run Code Online (Sandbox Code Playgroud)
问题是它在纵向上播放得很好但是当我将iPhone转为横向时,视频仍然以纵向而非横向播放:(应用中的所有视图控制器仅支持纵向.
我的MPMoviePlayerViewController子类只覆盖以下方法以允许方向更改,但它没有任何影响:
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
Run Code Online (Sandbox Code Playgroud)
我甚至尝试以编程方式旋转视频,但绝对没有运气,它始终保持纵向模式.
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation …Run Code Online (Sandbox Code Playgroud) iphone movie mpmovieplayercontroller orientation screen-orientation
我希望绘制一条曲线,直到它完全旋转并连接成一个完整的圆,只是圆形轮廓,没有填充.这必须在几秒钟内动画.
谁能指出我正确的方向?我已经问了一个类似的问题,但是我措辞不对,所以每个人都很难理解我的意思,因此它在问题的海洋中迷失了.
非常感谢您的帮助
[编辑]
我目前正在对UIView进行子类化并覆盖drawRect.我找到了绘制圆圈的代码,但我只需要笔画.
- (void)drawRect:(CGRect)rect {
// Drawing code
CGRect allRect = self.bounds;
CGRect circleRect = CGRectInset(allRect, 2.0f, 2.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
// Draw background
CGContextSetRGBStrokeColor(context, self.strokeValueRed, self.strokeValueGreen, self.strokeValueBlue, self.strokeValueAlpha); // white
CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 0.1f); // translucent white
CGContextSetLineWidth(context, self.lineWidth);
CGContextFillEllipseInRect(context, circleRect);
CGContextStrokeEllipseInRect(context, circleRect);
// Draw progress
CGPoint center = CGPointMake(allRect.size.width / 2, allRect.size.height / 2);
CGFloat radius = (allRect.size.width - 4) / 2;
CGFloat startAngle = - ((float)M_PI / 2); // 90 …Run Code Online (Sandbox Code Playgroud) 我有一个包含一个属性的swift协议:
protocol WireframeProtocol: class
{
var rootViewController: UIViewController { get }
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个实现此协议的类:
class MenuWireframe : WireframeProtocol
{
let rootViewController: UIViewController
init()
{
self.rootViewController = MenuViewController(nibName: "MenuViewController", bundle: nil)
(self.rootViewController as! MenuViewController).presenter = MenuPresenter(interactor: MenuInteractor())
}
}
Run Code Online (Sandbox Code Playgroud)
在我的Wireframe类中,变量实际上是MenuViewController类型,但必须声明为UIViewController以确认协议.我必须使用(self.rootViewController as!MenuViewController)将它向下转换为我想要的正确类,以便能够访问其属性.在我上面的简单示例中很好但是不是很易读,特别是在更复杂的情况下.有没有更好的方法来声明协议变量?
非常感谢!
我已使用外观属性将图像设置为我的应用中所有导航栏后退按钮的背景图像.我使用applicationDidLoad方法中的以下代码执行此操作.
UIImage *backButton = [UIImage imageNamed:@"btn-nav-back"];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButton forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
我的问题是,只要后退按钮出现,图像就会被拉伸,因为前一个视图的名称被设置为后退按钮的标题.是否有系统范围的方法我可以停止设置标题?同时尝试在实际视图控制器中将后退按钮的标题设置为空白无效:(
[self.navigationItem.backBarButtonItem setTitle:@""];
Run Code Online (Sandbox Code Playgroud) 我有一个动画,沿x轴稍微反弹一个视图.问题是使用旧的动画机制,并且作为文档状态建议iOS4 +使用基于块的动画.我想知道如何将这个简单的动画变成基于块的动画:
[UIView beginAnimations:@"bounce" context:nil];
[UIView setAnimationRepeatCount:2];
[UIView setAnimationRepeatAutoreverses:YES];
self.view.center = CGPointMake(self.view.center.x + 10, self.view.center.y);
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
此外,我希望视图在动画结束后返回其起始位置,上面的方法反弹视图并将其x值增加10个像素.
谢谢你的帮助.
我正在使用适用于iPhone的Facebook SDK.我需要能够在一个请求中检索经过身份验证的用户详细信息和个人资料图片.
在SDK的测试版中,我曾经可以使用下面的代码执行此操作,但现在只返回用户ID和图片网址.
[FBRequestConnection startWithGraphPath:@"me" parameters:[NSDictionary dictionaryWithObject:@"picture" forKey:@"fields"] HTTPMethod:@"GET" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)...
Run Code Online (Sandbox Code Playgroud)
有没有办法在一个请求中执行此操作?非常感谢任何建议.
[编辑]我也应该提一下,我需要直接映射到图像的URL字符串,因为我没有使用Facebook的新FBProfilePictureView类.
我正在使用当前的日期/时间[NSDate date].返回的值是将来一小时.我检查了我的手机位置和时间设置,它们是正确的.
我可以使用下面的代码将正确的日期和时间显示为字符串.
[NSDateFormatter localizedStringFromDate:[NSDate date] dateStyle:NSDateFormatterShortStyle
timeStyle:NSDateFormatterShortStyle]
Run Code Online (Sandbox Code Playgroud)
但我需要它将正确的日期/时间作为日期对象返回,因为我使用它来计算预计到达时间 -
[date dateByAddingTimeInterval:interval]
Run Code Online (Sandbox Code Playgroud)
我意识到我的问题类似于已经问过的问题,但没有一个答案符合我的需要.提前致谢!
iphone ×10
ios ×5
movie ×2
objective-c ×2
xcode ×2
animation ×1
facebook ×1
ios7 ×1
layout ×1
nsdate ×1
orientation ×1
swift ×1
templates ×1
uiappearance ×1
xcode4.5 ×1