Tag: 旋转

使用animateKeyframesWithDuration在屏幕上创build一个连续旋转的正方形

我试图用下面的代码在屏幕上创build一个连续旋转的正方形。 但我不知道为什么转速正在变化。 我怎样才能改变代码,使转速不变? 我尝试了不同的UIViewKeyframeAnimationOptions ,但似乎没有一个工作。 override func viewDidLoad() { super.viewDidLoad() let square = UIView() square.frame = CGRect(x: 55, y: 300, width: 40, height: 40) square.backgroundColor = UIColor.redColor() self.view.addSubview(square) let duration = 1.0 let delay = 0.0 let options = UIViewKeyframeAnimationOptions.Repeat UIView.animateKeyframesWithDuration(duration, delay: delay, options: options, animations: { let fullRotation = CGFloat(M_PI * 2) UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: […]

如何在sprite套件中用swift旋转sprite

嗨,我的问题是关于两个精灵的旋转。 当我触摸屏幕的右半边时,旋转开始并移动sprite2和sprite3。 如果我触摸屏幕的左半边,则旋转停止,因为速度= 0。如果再次触摸左半部分,则开始旋转。 但是,如果触摸与当前旋转方向相对应的屏幕的一半,则速度被复制。 我希望能够改变旋转的方向,但速度要保持不变。 video显示问题:http: //youtu.be/HxLwl1QZiNM import SpriteKit class GameScene: SKScene { let sprite = SKSpriteNode(imageNamed:"bWhite") let sprite2 = SKSpriteNode(imageNamed:"bBlue") let sprite3 = SKSpriteNode(imageNamed:"bRed") let circle = SKSpriteNode(imageNamed:"bCircle") override func didMoveToView(view: SKView) { /* Setup your scene here */ backColor = SKColor(red: 0, green: 0, blue: 0, alpha: 1) self.backgroundColor = backColor sprite.setScale(1.25) […]

在选项卡栏视图控制器中限制旋转

更新2 在我的UITabBarController子类中,我尝试添加这个: -(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; } 现在,每当我select一个标签项目,设备旋转到肖像模式完美。 但是,现在我可以在select(a)的同时旋转设备,设备将旋转到横向模式。 我怎样才能停止设备旋转? 我相信这个方法在我的选项卡控制器子类是什么导致这一点: – (BOOL)shouldAutorotate { if(self.selectedIndex == 0) { return NO; } return [self.viewControllers.lastObject shouldAutorotate]; } 如果我返回“否”,我不能旋转,当我在视图控制器中,但是当我select它,它不会自动旋转到肖像。 如果返回“是”,则可以在视图控制器中进行旋转,但是当select它时,会自动旋转为纵向。 我有一个自定义选项卡栏控制器在我的应用程序与以下层次结构: UITabBarController | UINavigationController | | | UIViewController(a) | UINavigationController | | | UIViewController(b) | UINavigationController | […]

如何在旋转的UIView中使用CGRectContainsPoint()

我有一个UIView ,用户可以点击UIView “select”或突出显示它所代表的应用程序内的“事物”。 我使用CGRectContainsPoint(thing.frame,tapPoint)来实现这一点,其中thing.frame是UIView的框架,而tapPoint是tapPoint中的轻敲点。 这工作完美。 ..通过设置transform属性(具有CGAffineTransform值)旋转UIView时。 当UIView像这样旋转时,该frame变成封装旋转视图的扁平正方形。 下面是这个问题的例子(框架属性被标记为A,而可视化的UIView框架被标记为B): 不旋转时 +——————+ | A == B | +——————+ 旋转时 +—————–+ | A . | | . . | | . . | | . . | | . B . | | . . | | . . | | . | +—————–+ 我想要捕获位于rect B ( UIView的真实边界,旋转的)范围内的水龙头,但不是当它们仅在rect […]

在iOS 7地图相机旋转上更新地图注释

我正在尝试获取它,以便在旋转iOS 7地图时,注释随相机标题一起旋转。 想象一下,我有针标注必须始终指向北方。 这看起来很简单,首先,应该有一个MKMapViewDelegate获取相机旋转,但没有。 我已经尝试使用地图代表然后查询地图视图的camera.heading对象,但首先这些代表似乎只是在旋转手势之前和之后调用一次: – (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated – (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated 我也尝试在camera.heading对象上使用KVO,但这不起作用,并且相机对象似乎是某种只在旋转手势完成时才更新的代理对象。 到目前为止,我最成功的方法是添加旋转手势识别器来计算旋转增量,并将其与在区域更改代表开始时报告的摄像头标题一起使用。 这可以工作到一个点,但在操作系统7中,你可以“轻弹”你的旋转手势,它增加了我似乎无法跟踪的速度。 有没有办法实时跟踪摄像头的方向? – (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated { heading = self.mapView.camera.heading; } – (void)rotationHandler:(UIRotationGestureRecognizer *)gesture { if(gesture.state == UIGestureRecognizerStateChanged) { CGFloat headingDelta = (gesture.rotation * (180.0/M_PI) ); headingDelta = fmod(headingDelta, 360.0); CGFloat newHeading = heading – headingDelta; [self updateCompassesWithHeading:actualHeading]; } } […]

每次单击button时将UIButton旋转90度

每次单击button时,如何将UIButton旋转90度,并跟踪每个旋转的位置/angular度? 这里是我到目前为止的代码,但它只能旋转一次: @IBAction func gameButton(sender: AnyObject) { UIView.animateWithDuration(0.05, animations: ({ self.gameButtonLabel.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2)) })) }

supportInterfaceOrientations更改时如何通知系统?

我的根视图控制器的supportedInterfaceOrientations的实现几乎总是返回UIInterfaceOrientationMaskAll ,但是有一个边界情况返回UIInterfaceOrientationMaskLandscape 。 这是工作,如果用户旋转设备。 但是,如果设备处于纵向模式,则不会调用supportedInterfaceOrientations方法,除非用户手动旋转设备。 我怎样才能以编程方式告诉系统这个方法的返回值已经改变了? 根据文档,似乎我应该能够调用[UIViewController attemptRotationToDeviceOrientation]但是这并没有任何效果( supportedInterfaceOrientations永远不会被调用,屏幕不旋转)。 我发现其他人已经发布了各种解决方法来尝试解决这个问题,但是他们都没有在我的testing中工作。 我怀疑他们可能在iOS 5.0中工作,但不是在iOS 6.0中工作。 我在根视图控制器的shouldAutorotate方法中返回YES 。

为什么在使用CGAffineTransformMakeRotation旋转视图时视图会改变位置

我有以下超级简单的animation,我基本上旋转一个视图从原来的angular度/中心2弧度,它旋转得很好我唯一的误解是为什么旋转发生时视图从原来的位置移动。 [UIView animateWithDuration:1.0 animations:^{ self.someView.transform = CGAffineTransformMakeRotation( 2 ); }]; 为什么用上面的代码旋转视图时会移动? 我目前正在尝试辨别CGAffineTransform参考中的信息。 了解定位点 。 我发现这个线程,但它没有显示具体的答案。 为什么旋转imageView,它改变位置? 非常感谢

节点旋转不遵循手指

我试图旋转一个箭头来跟随手指的移动,但它执行奇怪。 这绝对不是跟着它。 我试图在touchesMoved做。 我试图做到这一点: var fingerLocation = CGPoint() override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) { for touch: AnyObject in touches { fingerLocation = touch.locationInNode(self) let currentOrient = arrow.position let angle = atan2(currentOrient.y – fingerLocation.y, currentOrient.x – fingerLocation.y) let rotateAction = SKAction.rotateToAngle(angle + CGFloat(M_PI*0.5), duration: 0.0) arrow.runAction(rotateAction) } } 而且也试过这个: var fingerLocation = CGPoint() override […]

子视图控制器旋转方法不被调用

概要 我正在尝试将子视图控制器添加到父视图控制器,并有父视图控制器通知子视图控制器的旋转事件。 但是,旋转消息不会被转发到子视图控制器(这是默认行为)。 为什么这个默认行为不会发生? 环境:iOS 7,XCode 5,OSX 10.9 细节: 我正在按照Apple文档中的说明实现一个自定义容器视图控制器: “创build自定义容器视图控制器” 。 我试图build立一个简单的父母子女关系,转发轮换事件。 总层次结构如图14-1所示: ParentViewController ——–> RootView | / \ | / \ ˅ / \ ChildViewController —> ChildView \ \ OverLayView 我正在使用parentViewController(unityViewController = childViewController,unityView = childView)中的文件清单4-1中的代码完成此操作: // In the ParentViewController // Called by the Application Delegate in application:didFinishLaunchingWithOptions: – (void)addUnityViewController:(UIViewController *)unityViewController withUnityView:(UIView *)unityView { […]