小智 6
您可以将图像查看器用于Ionic 2+
npm install --save ionic-img-viewer
Run Code Online (Sandbox Code Playgroud)import { IonicImageViewerModule } from 'ionic-img-viewer'; @NgModule({ declarations: [ MyApp, HomePage ], imports: [ BrowserModule, IonicModule.forRoot(MyApp), IonicImageViewerModule ],
<img src ="IMAGE_URL"#myImage(click)="presentImage(myImage)"/>
Run Code Online (Sandbox Code Playgroud)import { ImageViewerController } from 'ionic-img-viewer'; export class MyPage { _imageViewerCtrl: ImageViewerController; constructor(imageViewerCtrl: ImageViewerController) { this._imageViewerCtrl = imageViewerCtrl; } presentImage(myImage) { const imageViewer = this._imageViewerCtrl.create(myImage); imageViewer.present(); } }
我在 Ionic 论坛上找到了这个解决方法:
html:
<ion-scroll (pinch)="pinchEvent($event)" scrollX="true" scrollY="true" zoom="true" style="width:100%;height:100%;text-align:center;">
<div [ngStyle]="{'background':'url('+src+') no-repeat','width' : width + 'px', 'height' : height + 'px', 'transform' : 'rotate('+rotacion+'deg)', 'background-size' : 'contain', 'background-position' : 'center'}" style="margin-top:50px;margin-bottom:50px;"></div>
</ion-scroll>
Run Code Online (Sandbox Code Playgroud)
.ts 方法:
pinchEvent(e) {
this.width = this.pinchW * e.scale;
this.height = this.pinchH * e.scale;
if(this.timeout == null){
this.timeout = setTimeout(() => {
this.timeout = null;
this.updateWidthHeightPinch();
}, 1000);
} else {
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
this.timeout = null;
this.updateWidthHeightPinch();
}, 1000);
}
}
updateWidthHeightPinch() {
this.pinchW = this.width;
this.pinchH = this.height;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8209 次 |
| 最近记录: |