控件旋转角度设置(swift)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了控件旋转角度设置(swift)相关的知识,希望对你有一定的参考价值。

参考技术A 实现以上图片旋转堆叠效果:

var orderImg =UIImageView()

            foriin0..<5

                letimg =  UIImageView()

                if(i==0)

                    orderImg = img

                    aboveView.addSubview(orderImg)

                else

                    aboveView.insertSubview(img, belowSubview: orderImg)

                    orderImg = img

               

                letaboveViewWidth =UIScreen.main.bounds.width*0.5

                letimgWidth =calculate(w:200.0)

                letimgHeight =calculate(wh:282.0, pwh:200.0, cpwh:imgWidth)

                letimgX = (aboveViewWidth-imgWidth)*0.5

                letimgY =calculate(h:70.0)

                img.frame=CGRect(x: imgX, y:imgY, width: imgWidth, height: imgHeight)

                img.image=UIImage(named:"select_small_photo")

                img.alpha=1-0.1*CGFloat(i)

                //自身的旋转点

                img.layer.anchorPoint=CGPoint(x:0.5, y:1.0)

                //相对于父控件的旋转点(img的父控件为aboveView)

                img.layer.position=CGPoint(x: imgX+imgWidth*0.5, y: imgY+imgHeight)

                //设置图片的旋转角度

                letangle = (CGFloat.pi/18.0)*CGFloat(i)

                img.transform=CGAffineTransform(rotationAngle: angle)

           

1、用frame,不要用Masonry或snap布局

2、anchorPoint和position两个属性必须要设置,否则显示的坐标有问题

osgEarth设置模型旋转角度

#include<windows.h>
#include <osgViewer/Viewer>
#include <osgEarthDrivers/gdal/GDALOptions>
#include <osg/ShapeDrawable>
#include <osgEarthUtil/EarthManipulator>
#include <osg/MatrixTransform>
#include <osgEarthFeatures/ConvertTypeFilter>
#include <osgEarthDrivers/model_simple/SimpleModelOptions>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/StateSetManipulator>

#ifdef _DEBUG
#pragma comment(lib, "osgd.lib")
//#pragma comment(lib, "osgDBd.lib")
#pragma comment(lib, "osgViewerd.lib")
#pragma comment(lib, "osgGAd.lib")
#pragma comment(lib, "osgEarthd.lib")
#pragma comment(lib, "osgEarthUtild.lib")
#else
#pragma comment(lib, "osg.lib")
#pragma comment(lib, "osgDB.lib")
#pragma comment(lib, "osgViewer.lib")
#pragma comment(lib, "osgGA.lib")
#endif // DEBUG


// lonlat1:雷达波圆锥顶点
// lonlat2:轨迹点
void rotateCone(osg::MatrixTransform* mt, const osgEarth::SpatialReference* sr, osg::Vec3d lonlat1, osg::Vec3d lonlat2)
{
    // 雷达波模型所在位置
    osgEarth::GeoPoint geoPoint1(
        sr,
        lonlat1.x(),
        lonlat1.y(),
        lonlat1.z(),
        osgEarth::ALTMODE_ABSOLUTE);
    osg::Matrixd matrix1;
    // 获取雷达波模型从原点变换到lonlat1位置的变换矩阵
    geoPoint1.createLocalToWorld(matrix1);
    // 经纬度高程到xyz的变换
    osg::Vec3d world1, world2;
    // geoPoint1.toWorld(world1);//等同于    sr->transformToWorld(lonlat1,world1);
    sr->transformToWorld(lonlat2, world2);
    // 计算轨迹点在雷达波模型坐标系下的位置
    osg::Vec3 point2InRadarCoordinateSystem = world2*osg::Matrix::inverse(matrix1);
    // 在雷达波模型坐标系下,对Z轴进行旋转,与连接原点指向轨迹点方向的矢量重合,计算出此旋转矩阵
    osg::Matrixd rotMat = osg::Matrixd::rotate(osg::Z_AXIS, point2InRadarCoordinateSystem-osg::Vec3(0,0,0));
    // 将计算出的旋转矩阵赋给雷达波模型所在的mt
    mt->setMatrix(rotMat);
}
int main(int argc, char** argv)
{
    osgViewer::Viewer viewer;
    std::string world_tif = "data/world.tif";
    osgEarth::Map* map = new osgEarth::Map();
    // Start with a basemap imagery layer; we‘ll be using the GDAL driver
    // to load a local GeoTIFF file:
    osgEarth::Drivers::GDALOptions basemapOpt;
    basemapOpt.url() = world_tif;
    map->addImageLayer(new osgEarth::ImageLayer(osgEarth::ImageLayerOptions("basemap", basemapOpt)));

    osgEarth::MapNodeOptions mapNodeOptions;
    mapNodeOptions.enableLighting() = false;
    osgEarth::MapNode* mapNode = new osgEarth::MapNode(map, mapNodeOptions);

    osgEarth::Drivers::SimpleModelOptions opt;
    opt.location() = osg::Vec3(118, 40, 10000);
    //opt.url() = "cow.osg.1000,1000,1000.scale";
    osg::Geode* geode = new osg::Geode;
    osg::ShapeDrawable* cone = new osg::ShapeDrawable(new osg::Cone(osg::Vec3(), 10000, 50000));
    //osg::ShapeDrawable* cone = new osg::ShapeDrawable(new osg::Box(osg::Vec3(), 50000));
    geode->addDrawable(cone);
    osg::MatrixTransform* mtCone = new osg::MatrixTransform;
    mtCone->addChild(geode);
    opt.node() = mtCone;
    map->addModelLayer(new osgEarth::ModelLayer("", opt));

    rotateCone(mtCone, map->getProfile()->getSRS(), osg::Vec3(118, 40, 100), osg::Vec3(120, 40, 100));

    osg::Group* root = new osg::Group();
    root->addChild(mapNode);
    viewer.setSceneData(root);
    viewer.setCameraManipulator(new osgEarth::Util::EarthManipulator());

    // Process cmdline args
    //MapNodeHelper().parse(mapNode, arguments, &viewer, root, new LabelControl("Features Demo"));

    //视点定位模型所在位置
    osgEarth::Viewpoint vp("", 118, 40, 1000.0, -2.50, -90.0, 1.5e6);
    (dynamic_cast<osgEarth::Util::EarthManipulator*>(viewer.getCameraManipulator()))->setViewpoint(vp);

    // add some stock OSG handlers:
    viewer.addEventHandler(new osgViewer::StatsHandler());
    viewer.addEventHandler(new osgViewer::WindowSizeHandler());
    viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
    viewer.setUpViewInWindow(100, 500, 1024, 768);
    return viewer.run();
}

 

以上是关于控件旋转角度设置(swift)的主要内容,如果未能解决你的问题,请参考以下文章

暂停动画旋转,设置角度值,然后稍后恢复?

iOS Swift 检测图像旋转

emwin时钟指针如何旋转

android控件随手势旋转

Android自定义控件之可平移、缩放、旋转图片控件

Android 旋转动画怎么动态设置旋转角度,用