1. 程式人生 > >flex4類似於Safari佈局圖片牆佈局

flex4類似於Safari佈局圖片牆佈局

package  {
	import flash.geom.Matrix3D;
	import flash.geom.PerspectiveProjection;
	import flash.geom.Point;
	import flash.geom.Vector3D;
	
	import mx.controls.Alert;
	import mx.controls.Image;
	import mx.core.IVisualElement;
	import mx.core.UIComponent;
	
	import spark.filters.GlowFilter;
	import spark.layouts.supportClasses.LayoutBase;
	
	/**
	 * Flex 4,
	 * @author Qiang JiShen
	 * 類似於Safari佈局
	 */
	
	public class TopSiteLayout extends LayoutBase {
		
		private var _columnWidth:Number;
		private var _rowHeight:Number;
		private var _columns:int;
		private var _rows:int;
		
		private var isColumnWidthSet:Boolean;
		private var isRowHeightSet:Boolean;
		private var isColumnsSet:Boolean;
		private var isRowsSet:Boolean;
		
		private var _horizontalGap:Number;
		private var _verticalGap:Number;
		
		private var rotatingAngle:Number;
		private var radius:Number;
		private var cameraPosition:Number;
		private var chordLength:Number;
		private var arcLength:Number;
		
		public static var VIEW_ANGLE:Number = 140;
		
		public function TopSiteLayout() {
			super();
			_columnWidth = 0;
			_rowHeight = 0;
			_rows = 0;
			_horizontalGap = 0;
			_verticalGap = 0;
		}
		
		/**
		 * Specifies the width in pixels of each column. If not specified
		 * the width will be auto calculated depending on the width of the target
		 * and the number of columns
		 */
		public function get columnWidth():Number {
			return _columnWidth;
		}
		
		public function set columnWidth(value:Number):void {
			_columnWidth = value;
			isColumnWidthSet = true;
		}
		
		/**
		 * Specifies the height in pixels of each row. If not specified
		 * the height will be auto calculated depending on the height of the target
		 * and the number of rows
		 */
		public function get rowHeight():Number {
			return _rowHeight;
		}
		
		public function set rowHeight(value:Number):void {
			_rowHeight = value;
			isRowHeightSet = true;
		}
		
		/**
		 * The number of columns to display. If not specified
		 * the number will be self determined
		 */
		public function get columns():int {
			return _columns;
		}
		
		public function set columns(value:int):void {
			_columns = value;
			isColumnsSet = true;
		}
		
		/**
		 * The number of rows to display. If not specified
		 * the number will be self determined
		 */
		public function get rows():int {
			return _rows;
		}
		
		public function set rows(value:int):void {
			_rows = value;
			isRowsSet = true;
		}
		
		/**
		 * The space in pixels between two rows
		 */
		public function get horizontalGap():Number {
			return _horizontalGap;
		}
		
		public function set horizontalGap(value:Number):void {
			_horizontalGap = value;
		}
		
		/**
		 * The space in pixels between two columns
		 */
		public function get verticalGap():Number {
			return _verticalGap;
		}
		
		public function set verticalGap(value:Number):void {
			_verticalGap = value;
		}
		
		override public function updateDisplayList(width:Number, height:Number):void {
			calculateRowsCols();
			chordLength = width;
			calculateRadiusAndArc(width, height);
			
			
			
			var degreesMove:Number = rotatingAngle / (_columns - 1);
			if (isNaN(degreesMove))
				degreesMove = 0;
			var startDegree:Number = -rotatingAngle / 2;
			
			for (var i:int = 0; i < _rows; i++) {
				for (var j:int = 0; j < _columns; j++) {
					var index:int = i * _columns + j;
					if (index >= target.numElements) {
						return;
					}
					var element:IVisualElement = target.getVirtualElementAt(index);
					element.setLayoutBoundsSize(_columnWidth, _rowHeight, true);
					
					var pp:PerspectiveProjection = new PerspectiveProjection();
					pp.fieldOfView = 15;
					pp.projectionCenter = new Point(width / 2, height / 2);
					
					element["transform"].perspectiveProjection = pp;
					
					var matrix:Matrix3D = new Matrix3D();
					matrix.appendTranslation(-_columnWidth / 2.5, 0, radius);
					matrix.appendRotation(startDegree + degreesMove * j, Vector3D.Y_AXIS);
					matrix.appendTranslation(width / 2, (_rowHeight + _horizontalGap) * i, -cameraPosition);
					element.setLayoutMatrix3D(matrix, false);
				}
			}
		
		}
		
		protected function calculateRadiusAndArc(width:Number, height:Number):void {
			
			var viewAngleRadians:Number = VIEW_ANGLE * Math.PI / 180;
			
			//chordLength = 2r * sin (angle/2);
			var sinus:Number = Math.sin(viewAngleRadians);
			radius = chordLength / (2 * Math.sin(viewAngleRadians / 2));
			
			//chordLength = 2*Math.sqrt(r*r - h*h)
			cameraPosition = Math.sqrt(4 * radius * radius - chordLength * chordLength) / 2;
			
			//arcLength 
			arcLength = viewAngleRadians * radius;
			
			measureRowsColsWidth(arcLength, height);
			
			//the old length of the arc minus width for element
			//half for the left, half for the right
			var newArcLength:Number = arcLength - (_columnWidth + _verticalGap);
			
			//the angle of the new arc, a.k.a the allowed degrees move
			var rotatingAngleRadians:Number = newArcLength / radius
			rotatingAngle = rotatingAngleRadians * 180 / Math.PI;
		}
		
		private function measureRowsColsWidth(width:Number, height:Number):void {
			if (isRowHeightSet == false) {
				_rowHeight = (height - _rows * _horizontalGap) / _rows;
			}
			
			if (isColumnWidthSet == false) {
				_columnWidth = (width - _columns * _verticalGap) / _columns;
			}
		}
		
		private function calculateRowsCols():void {
			if (isColumnsSet == false && isRowsSet == false) {
				_columns = Math.ceil(Math.sqrt(target.numElements));
				_rows = Math.ceil(target.numElements / _columns);
			} else if (isColumnsSet == false) {
				_columns = Math.ceil(target.numElements / _rows);
			} else if (isRowsSet == false) {
				_rows = Math.ceil(target.numElements / _columns);
			}
		}
	}
}

2.使用

         <s:layout>
            <util:TopSiteLayout columns="4" rows="4"/>
        </s:layout>


相關推薦

flex4類似Safari佈局圖片佈局

package { import flash.geom.Matrix3D; import flash.geom.PerspectiveProjection; import flash.geom.Point; import flash.geom.Vector3D;

查看圖片插件--Viewer(類似qq和微信聊天 的查看圖片

方法 標簽 ott meet 定義函數 更新 article 調用 show Viewer的github地址:https://github.com/fengyuanchen/viewer 下載該插件(在文件夾dist裏面) 具有參考價值的幾個網站:http://www.d

邊界圓角 盒模型佈局 圖片背景 精靈圖

常用標籤的使用: 直接舉例: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>常用標籤

JSP綜合例項-應用DIV+CSS佈局許願主介面

樣圖如下: HTML程式碼如下:  <!doctype html> <html> <head> <meta charset="utf-8"> <title>index</title> <link

圖片佈局,string等)打進jar包

解決如下:由於打包出來的jar只有原始碼的.class 檔案,不包含資原始檔,我們就把jar包中用到的資源放到你使用 該jar的工程裡面。然後通過反射即可,這裡給出反射類: public class MResource { public static int getIdByName(Context co

textview中點選效果實現,比如點選textview中實現圖片和文字的顏色變化(類似button)

<TextView android:drawableTop="@drawable/bg_text_view" android:id="@+id/home_toolbar_settings" an

iOS實現文字環繞圖片textView佈局

_imageView.frame  = CGRectMake(_imageView.frame.origin.x,_imageViewY-scrollView.contentOffset.y,_imageView.frame.size.width , _imageView.frame.size.he

bootstrap 佈局圖片列表

 <%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://jav

實現類似QQ空間相簿的點選圖片放大,再點後縮小回原來位置

package com.kale.gridviewanimtest; import android.graphics.Point; import android.graphics.Rect; import android.view.View; import android.view.Vie

ul+li實現類似table的自適應寬度佈局

<div class="cart-panel"> <div class="hd"> <ul class="order-title"> <li class="product">商品名稱</li>

Android自定義控制元件圖片+文字佈局

原本想用Tabrow來佈局一組上面是圖片下面是文字說明的控制元件,但是發現Tabrow不像想象的那樣簡易,而且這幾組之間的控制元件距離不好把握,在網上找了兩種方法以供參照。 方法一、利用RadioButton巧妙的實現佈局 <LinearLayout

響應式佈局-圖片列表如何在窄屏(768px)中顯示為有間隙的一行

       摘要:本文旨在介紹在寬屏(>768px)中圖片列表中如何顯示為有固定間隙的一行排列,介紹了筆者自己嘗試過得五種寫法,並分析了其缺點,採用什麼方法就得見人見智,具體情況具體分析了。         如何在窄屏(<320px)中顯示為一列呢,做出的顯示

iOS 圖片部分模糊,類似美圖秀秀

else false ati only ash created int 使用 last 代碼地址如下:http://www.demodashi.com/demo/14277.html 演示效果 演示效果 代碼結構 項目結構截圖如下: 該模塊的核心源碼部分為

淺析在QtWidget中自定義Model(beginInsertRows()和endInsertRows()是空架子,類似一種信號,用來通知底層)

cti ron 初學者 開發 http 沒有 insert ati 學習 Qt 4推出了一組新的item view類,它們使用model/view結構來管理數據與表示層的關系。這種結構帶來的功能上的分離給了開發人員更大的彈性來定制數據項的表示,它也提供一個標準的model接

mysql下分組取關聯表指定提示方法,類似mssql中的cross apply

nbsp cts ont font ack you 方法 sta lease 轉至:https://stackoverflow.com/questions/12113699/get-top-n-records-for-each-group-of-grouped-result

Uva 10003 Cutting Sticks (類似最優矩陣連乘的dp)

out min 分析 sin [] can 任務 cin algo 題意:有一根長度為L的木棍,和n個切割點的位置(按照從小到大排序),你的任務是在這些切割點的位置把棍子切成n+1份,使得總切割費用最小。每次切割的費用等於被切的木棍長度 思路:這道題與最優矩陣連乘的思想一樣

iOS 裁剪圓形圖像並顯示(類似微信頭像)

ios 圓形頭像 裁剪 圓形 本文主要講解如何從照片庫選擇一張照片後將其裁剪成圓形頭像並顯示,類似於微信頭像那種模式。 本文的方法也適用於當時拍照獲取的圖像,方法類似,所以不再贅述。 本文主要是在iOS 10環境下使用,此時如果要使用使用系統照片庫、照相機等功能需要授權

vs2013/2015中scanf函數類似error C4996: 'scanf': This function or variable may be unsafe的安全檢查錯誤

span 調試 ria 安全性 init 點擊 scan online pan   在使用vs2015時,遇到了scnaf函數安全性的問題,程序不能正常運行,錯誤如下: error C4996: ‘scanf‘: This function or variable may

簡單的切換頁面(類似微信)

stat urn ima http end elf int idt lis //在App.js中實現import React from ‘react‘; import { StyleSheet, Text, View } from ‘react-native‘; impo

用nodejs搭建類似C++的服務器後臺.類似網易pomelo

情況 分享 .cn 朋友 簡單 .com 結構 ejs 父進程 實際的情況,用nodejs跑業務,非常的快,只要用好其無阻塞和回調這兩點,處理速度真的是杠杠的。 從年初開始,我用nodejs搭建了類似C++的服務器後臺,也想和做同樣的事情的朋友分享,本服務平臺因為已經實際商