Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIP检测识别器-带CATTransferM3D的TranslationView_Ios_Core Animation_Uipangesturerecognizer_Catransform3d_Catransform3drotate - Fatal编程技术网

Ios UIP检测识别器-带CATTransferM3D的TranslationView

Ios UIP检测识别器-带CATTransferM3D的TranslationView,ios,core-animation,uipangesturerecognizer,catransform3d,catransform3drotate,Ios,Core Animation,Uipangesturerecognizer,Catransform3d,Catransform3drotate,我正在尝试使用UIPangestureRecognitor实现翻页动画。代码如下: - (void)handlePan:(UIPanGestureRecognizer *)recognizer { CGPoint location = [recognizer locationInView:self.view]; CGPoint translation = [recognizer translationInView:self.view]; CGPoint velocity

我正在尝试使用UIPangestureRecognitor实现翻页动画。代码如下:

- (void)handlePan:(UIPanGestureRecognizer *)recognizer {

    CGPoint location = [recognizer locationInView:self.view];
    CGPoint translation = [recognizer translationInView:self.view];
    CGPoint velocity = [recognizer velocityInView:self.view];

    [recognizer setTranslation:CGPointZero inView:recognizer.view];

switch (recognizer.state) {
        case UIGestureRecognizerStateChanged:
        {

            self.currentTranslation = self.currentTranslation + translation.x;

            //only pan left
            if (self.currentTranslation > 0.0) {
                self.currentTranslation = 0.0;
            }


            CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
            rotationAndPerspectiveTransform.m34 = 1.0 / -2000;

            self.currentRotation = self.currentTranslation/2 * M_PI / 180.0f;
            //dont rotate past -90 degrees
            if (self.currentRotation <= -M_PI/2) {
                self.currentRotation = -M_PI/2+0.0001;
            }
            rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, self.currentRotation, 0.0f, 1.0f, 0.0f);

            float ypos = self.view.layer.position.y;

            self.view.layer.anchorPoint = CGPointMake(0, 0.5);
            self.view.layer.position = CGPointMake(0, ypos);        
            self.view.layer.transform = rotationAndPerspectiveTransform;


            break;
        }


        default:
            break;
    }

}
-(void)handlePan:(UIPangestureRecognitor*)识别器{
CGPoint location=[识别器位置视图:self.view];
CGPoint translation=[识别器translationView:self.view];
CGPoint-velocity=[识别器速度视图:self.view];
[识别器setTranslation:CGPointZero-inView:recognizer.view];
开关(识别器状态){
案例UIgestureRecognitzerStateChanged:
{
self.currentTranslation=self.currentTranslation+translation.x;
//只剩下平底锅了
如果(self.currentTranslation>0.0){
self.currentTranslation=0.0;
}
CATTransferM3D旋转和透视变换=CATTransferM3D实体;
rotationAndPerspectiveTransform.m34=1.0/-2000;
self.currentRotation=self.currentTranslation/2*M_PI/180.0f;
//不要旋转超过-90度

如果(self.currentRotation转换已累积。请在案例UIgestureRecognitizerStateChanged后将其添加到代码中

    [recognizer setTranslation:CGPointZero inView:self.view];

请注意,我在上面的代码中已经提到了这一点。我认为随着角度变大,旋转效果看起来更极端,这是一个更大的问题。我认为平移本身是线性的。我只需要找出如何抑制旋转。@c我想你的self.currentTranslation是累积的。请尝试使用translation.x而不是of在CATTransferM3dRotate中添加到self.currentTranslation。我相信这就是问题所在。